Forum Discussion

Tony2021's avatar
Tony2021
Steel Contributor
Dec 20, 2021

OpenArgs, Zero Length String Error

Hello experts,

 

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
Else
     '/this is a new record
     Me.FirstName = Split(Me.OpenArgs, ";")(0)
     Me.CompanyID = Split(Me.OpenArgs, ";")(1)
End If
End If

 

 

I get a Zero Length string error on sbfrmContacts FirstName:

 

  • Hi,

    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.

     

    Servus
    Karl
    Access News

  • arnel_gp's avatar
    arnel_gp
    Steel Contributor

    Tony2021 

    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.

    • Tony2021's avatar
      Tony2021
      Steel Contributor
      excellent. thanks Arnel. I will test that. I think the Response = acDataErrAdded goes in the Not in List event if not mistaken.
      • arnel_gp's avatar
        arnel_gp
        Steel Contributor
        Yes after you Open the Other form and the record is asded to it.
  • Hi,

    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.

     

    Servus
    Karl
    Access News

    • Tony2021's avatar
      Tony2021
      Steel Contributor
      Perfect! I will remember that. Does it matter if I use a ! or a . ? I see the same property is there regardless if I use either one. thanks for the help. Works great!

Resources