S
Steve
I am atttempting to use the same multiselect list box form in a couple places
in my application by using "openArgs" to determine which button open the form
and then redefining the list box row sources depending on the openArgs. One
of the features on this form is the ability to add user defined choices to
the listbox list using the following code. I have attempted to define the
name of the field the new list item will be placed using a string variable
but this does not seem to work. (see arrows)
Private Sub AddToList_Click()
On Error GoTo Err_AddToList_Click
Dim db As Database
Dim rstCathList As DAO.Recordset
Dim AddStr As String
Dim strField as String '<--define variable as string
If OpenArgs = "TestForm" Then
strField = "TestList" '<--using openArgs to determine which field to
update
End If
AddStr = [NewItem]
Set db = CurrentDb
Set rstCathList = db.OpenRecordset(strRecordset)
rstCathList.AddNew
rstCathList!strField = AddStr '<--rstCathList!strField is not recognized
rstCathList.Update
Me.Refresh
Exit_AddToList_Click:
Exit Sub
Err_AddToList_Click:
MsgBox Err.Description
Resume Exit_AddToList_Click
End Sub
in my application by using "openArgs" to determine which button open the form
and then redefining the list box row sources depending on the openArgs. One
of the features on this form is the ability to add user defined choices to
the listbox list using the following code. I have attempted to define the
name of the field the new list item will be placed using a string variable
but this does not seem to work. (see arrows)
Private Sub AddToList_Click()
On Error GoTo Err_AddToList_Click
Dim db As Database
Dim rstCathList As DAO.Recordset
Dim AddStr As String
Dim strField as String '<--define variable as string
If OpenArgs = "TestForm" Then
strField = "TestList" '<--using openArgs to determine which field to
update
End If
AddStr = [NewItem]
Set db = CurrentDb
Set rstCathList = db.OpenRecordset(strRecordset)
rstCathList.AddNew
rstCathList!strField = AddStr '<--rstCathList!strField is not recognized
rstCathList.Update
Me.Refresh
Exit_AddToList_Click:
Exit Sub
Err_AddToList_Click:
MsgBox Err.Description
Resume Exit_AddToList_Click
End Sub