Hi,
I'm trying to fix a contacts database problem. The main form "contacts" has a command button to open a "names" form in which to view names associated with a specific contact (contactID is primary key on main form). I can page through the names just fine, but when I go to add a new name, the contactID goes back to 0.
The code for the command button and names form are below. Thanks in advance for any help you can offer.
Tom
Here's the code for the command button on the main "contacts" form:
Private Sub Command50_Click()
On Error GoTo Err_Command50_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Names"
stLinkCriteria = "[ContactID]=" & Me![ContactID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
'Form_Contacts.Requery
Exit_Command50_Click:
Exit Sub
Err_Command50_Click:
MsgBox Err.Description
Resume Exit_Command50_Click
End Sub
Heres the code for the names form:
On Error GoTo Err_cmdNextRec_Click
DoCmd.GoToRecord , , acNext
Exit_cmdNextRec_Click:
Exit Sub
Err_cmdNextRec_Click:
MsgBox Err.Description
Resume Exit_cmdNextRec_Click
End Sub
Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click
DoCmd.GoToRecord , , acNewRec
Exit_cmdAdd_Click:
Exit Sub
Err_cmdAdd_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_Click
End Sub
Private Sub delete_Click()
On Error GoTo Err_delete_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit_delete_Click:
Exit Sub
Err_delete_Click:
MsgBox Err.Description
Resume Exit_delete_Click
End Sub
Private Sub Form_Load()
End Sub
Private Sub save_Click()
On Error GoTo Err_save_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_save_Click:
Exit Sub
Err_save_Click:
MsgBox Err.Description
Resume Exit_save_Click
End Sub
I'm trying to fix a contacts database problem. The main form "contacts" has a command button to open a "names" form in which to view names associated with a specific contact (contactID is primary key on main form). I can page through the names just fine, but when I go to add a new name, the contactID goes back to 0.
The code for the command button and names form are below. Thanks in advance for any help you can offer.
Tom
Here's the code for the command button on the main "contacts" form:
Private Sub Command50_Click()
On Error GoTo Err_Command50_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Names"
stLinkCriteria = "[ContactID]=" & Me![ContactID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
'Form_Contacts.Requery
Exit_Command50_Click:
Exit Sub
Err_Command50_Click:
MsgBox Err.Description
Resume Exit_Command50_Click
End Sub
Heres the code for the names form:
On Error GoTo Err_cmdNextRec_Click
DoCmd.GoToRecord , , acNext
Exit_cmdNextRec_Click:
Exit Sub
Err_cmdNextRec_Click:
MsgBox Err.Description
Resume Exit_cmdNextRec_Click
End Sub
Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click
DoCmd.GoToRecord , , acNewRec
Exit_cmdAdd_Click:
Exit Sub
Err_cmdAdd_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_Click
End Sub
Private Sub delete_Click()
On Error GoTo Err_delete_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit_delete_Click:
Exit Sub
Err_delete_Click:
MsgBox Err.Description
Resume Exit_delete_Click
End Sub
Private Sub Form_Load()
End Sub
Private Sub save_Click()
On Error GoTo Err_save_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_save_Click:
Exit Sub
Err_save_Click:
MsgBox Err.Description
Resume Exit_save_Click
End Sub