Dec 19 2021 06:11 PM
Dec 19 2021 06:11 PM
I am trying to grab the name that I type in a combo box field (cboSentTo) and also grab the Me.txtCOID.
The below grabs the txtCOID but it doesnt grab what I type in the Me.cboSentTo (get a zero length string error). I type in the person's name in Me.cboSentTo and tab out and the codes below fire but that name I typed in the cboSentTo doesnt appear in the FirstName field in the sbfrmContacts
Do you happen to see where the error is? I am thinking it has something to do with "string" since what I type in Me.cboSentTo is a string and Me.txtCOID is not a string but I dont really know since I am not a programmer. thank you
Below are my codes.
Private Sub cboSentTo_NotInList(NewData As String, Response As Integer)
DoCmd.OpenForm "sbfrmContacts", , , , acFormAdd, acDialog, OpenArgs:=Me.cboSentTo & ";" & Me.txtCOID & ";" '& Me.txtProjectID & ";"
sbfrmContacts On Load Event:
Private Sub Form_Load()
If Nz(Me.OpenArgs, "") <> "" Then
If Not Me.NewRecord Then
Me.Filter = "[FirstName] = " & Split(Me.OpenArgs, ";")(0) & " AND [CompanyID] = " & Split(Me.OpenArgs, ";")(1)
Me.FilterOn = True
'/this is a new record
Me.FirstName = Split(Me.OpenArgs, ";")(0)
Me.CompanyID = Split(Me.OpenArgs, ";")(1)
I get a Zero Length string error on sbfrmContacts FirstName:
Dec 20 2021 05:00 AM - edited Dec 20 2021 05:01 AMSolution
Instead of Me.cboSentTo try this: Me!cboSentTo.Text
Since your code is in the NotInList event of the combo box, what you've typed in is not saved as its value yet, but you can already grab it with the text property.
Dec 20 2021 04:24 PM
Dec 20 2021 05:02 PM
when the Item you typed on the combo is Not In the List,
the Not On the List event is triggered and is passed the value you type to the event (as NewData).
you passed this value when you Open the Second form:
DoCmd.OpenForm "sbfrmContacts", , , , acFormAdd, acDialog, OpenArgs:=NewData & ";" & Me.txtCOID & ";" '& Me.txtProjectID & ";"
then you set the Response of the event to:
Response = acDataErrAdded
the above code will update your combobox.
Dec 20 2021 07:44 PM