I am having a hard time passing an object to a subroutine/function which is referred to using the bang operator. I have a number of comboboxes using lookup tables on a form and I want to use just one subroutine/function to do the NotInList checking before adding. Here's some code so far:
Sub ItemNotInList(NewData As String, Response As Integer, Tbl As String, FldName as ???)
Dim Msg As String, Answer As Integer
Dim dbs As Database, rst As DAO.Recordset
Answer = MsgBox(StrConv(NewData, vbProperCase) & " does not exist." & Chr(10) & "@Do you want to add it?@ ", _
vbQuestion + vbYesNo + vbDefaultButton2, "Item Type"
Response = acDataErrContinue
If Answer = vbNo Then Exit Sub
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset(Tbl, dbOpenDynaset)
With rst
.AddNew
!FldName= NewData
.Update
.Bookmark = .LastModified
.Close
End With
Response = acDataErrAdded
dbs.Close
End Sub
Now, what kind of variable should FldName be, and how can I set the value of rst!FldName ?
Thanks in advance for the help.
Sub ItemNotInList(NewData As String, Response As Integer, Tbl As String, FldName as ???)
Dim Msg As String, Answer As Integer
Dim dbs As Database, rst As DAO.Recordset
Answer = MsgBox(StrConv(NewData, vbProperCase) & " does not exist." & Chr(10) & "@Do you want to add it?@ ", _
vbQuestion + vbYesNo + vbDefaultButton2, "Item Type"
Response = acDataErrContinue
If Answer = vbNo Then Exit Sub
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset(Tbl, dbOpenDynaset)
With rst
.AddNew
!FldName= NewData
.Update
.Bookmark = .LastModified
.Close
End With
Response = acDataErrAdded
dbs.Close
End Sub
Now, what kind of variable should FldName be, and how can I set the value of rst!FldName ?
Thanks in advance for the help.