On June 24 I posted a request and Colin Essex replied to my post by suggesting a way to add an entry to a combo box if not already in the source table. I really like the simplicity of this method, however, I'm getting a run time error that I can't figure out how to fix. Here is my code:
Private Sub ClientCity_NotInList(NewData As String, Response As Integer)
Dim rst As Recordset
Dim strTableName
If MsgBox("Entry not in list, would you like to add it now?", vbOKCancel, "Add City") = vbOK Then
Set rst = CurrentDb.OpenRecordset("tblCities")
rst.AddNew
rst!City = NewData
rst.Update
Set rst = Nothing
Response = acDataErrAdded
Else
Response = acDataErrContinue
ClientCity.Undo
End If
End Sub
The error is run time error '13': Type mismatch (which I know has to do with the data type), but when debugging the code, on the line rst!City = New Data, I get the following message:
rst!City = <Object variable or With block variable not set>.
The table consists of an AutoNumber primary key (CityID) and a text field (City). Can anyone tell me what I'm not seeing??
Thanks!!
Judy
Private Sub ClientCity_NotInList(NewData As String, Response As Integer)
Dim rst As Recordset
Dim strTableName
If MsgBox("Entry not in list, would you like to add it now?", vbOKCancel, "Add City") = vbOK Then
Set rst = CurrentDb.OpenRecordset("tblCities")
rst.AddNew
rst!City = NewData
rst.Update
Set rst = Nothing
Response = acDataErrAdded
Else
Response = acDataErrContinue
ClientCity.Undo
End If
End Sub
The error is run time error '13': Type mismatch (which I know has to do with the data type), but when debugging the code, on the line rst!City = New Data, I get the following message:
rst!City = <Object variable or With block variable not set>.
The table consists of an AutoNumber primary key (CityID) and a text field (City). Can anyone tell me what I'm not seeing??
Thanks!!
Judy