A
Amit
Hi,
This is a follow-up to my earlier post re: compile error.
I got some suggestions from Graham, but I'm stuck now, and
will appreciate help!!!
I'm using a button to insert the values selected in the
list on a form.
Here's the code:
====================================
Private Sub cmdSaveRecord_Click()
On Error GoTo Err_cmdSaveRecord_Click
Dim varItem As Variant
Dim strSql As String
Dim db As DAO.Database
Set db = CurrentDb()
For Each varItem In Me.List2.ItemsSelected
strSql = "Insert Into tblPersonColor (PersonID,
ColorID) Values (" & _
Me.ID & ",'" & Me.List2.ItemData(varItem)
& "')"
db.Execute strSql
Next varItem
Set db = Nothing
' Screen.PreviousControl.SetFocus
' DoCmd.FindNext
Exit_cmdSaveRecord_Click:
Exit Sub
Err_cmdSaveRecord_Click:
MsgBox Err.Description
Resume Exit_cmdSaveRecord_Click
End Sub
=====================================
Here's the history:
1. The code was giving me a compile error
2. I commented out the line ("Dim db As DAO.Database") and
it worked fine (values were inserted into the table)
3. Following Graham's suggestion, I uncommented the line,
made changes in 'Tools-->Reference' etc. and successfully
compiled the code.
4. Don't get any compile errors, but the values are not
being inserted into the table now.
Please help!!
-Amit
This is a follow-up to my earlier post re: compile error.
I got some suggestions from Graham, but I'm stuck now, and
will appreciate help!!!
I'm using a button to insert the values selected in the
list on a form.
Here's the code:
====================================
Private Sub cmdSaveRecord_Click()
On Error GoTo Err_cmdSaveRecord_Click
Dim varItem As Variant
Dim strSql As String
Dim db As DAO.Database
Set db = CurrentDb()
For Each varItem In Me.List2.ItemsSelected
strSql = "Insert Into tblPersonColor (PersonID,
ColorID) Values (" & _
Me.ID & ",'" & Me.List2.ItemData(varItem)
& "')"
db.Execute strSql
Next varItem
Set db = Nothing
' Screen.PreviousControl.SetFocus
' DoCmd.FindNext
Exit_cmdSaveRecord_Click:
Exit Sub
Err_cmdSaveRecord_Click:
MsgBox Err.Description
Resume Exit_cmdSaveRecord_Click
End Sub
=====================================
Here's the history:
1. The code was giving me a compile error
2. I commented out the line ("Dim db As DAO.Database") and
it worked fine (values were inserted into the table)
3. Following Graham's suggestion, I uncommented the line,
made changes in 'Tools-->Reference' etc. and successfully
compiled the code.
4. Don't get any compile errors, but the values are not
being inserted into the table now.
Please help!!
-Amit