Hi There,
I have a form 'Players' which has a field called Contact. When adding a new record to the Players form, the user has to select an existing contact or add a new one (they cant just type in a name).
(There is a contacts table)
So, i want a button next to the contacts field.I want it to:
1. If there is already a contact selected on the form, the contacts form open at this contact, so can be edited.
2. If there is no contact selected, the button will take the user to the contacts form, but will display the first record in the contacts table. From here the user can select the contact they want.
This is what i have (code below). With this code, if there is a contact already entered, the contacts form loads with that contact select, which is correct. However, if no contact has been selected, the contacts form opens with a blank record; whereas i want it to open at first record!
Private Sub Command90_Click()
On Error GoTo Err_Command90_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmContacts"
If Me.Contact = " " Then
DoCmd.OpenForm stDocName
Else
stLinkCriteria = "[Name]=" & "'" & Me![Contact] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Exit_Command90_Click:
Exit Sub
Err_Command90_Click:
MsgBox Err.Description
Resume Exit_Command90_Click
End Sub
I have a form 'Players' which has a field called Contact. When adding a new record to the Players form, the user has to select an existing contact or add a new one (they cant just type in a name).
(There is a contacts table)
So, i want a button next to the contacts field.I want it to:
1. If there is already a contact selected on the form, the contacts form open at this contact, so can be edited.
2. If there is no contact selected, the button will take the user to the contacts form, but will display the first record in the contacts table. From here the user can select the contact they want.
This is what i have (code below). With this code, if there is a contact already entered, the contacts form loads with that contact select, which is correct. However, if no contact has been selected, the contacts form opens with a blank record; whereas i want it to open at first record!
Private Sub Command90_Click()
On Error GoTo Err_Command90_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmContacts"
If Me.Contact = " " Then
DoCmd.OpenForm stDocName
Else
stLinkCriteria = "[Name]=" & "'" & Me![Contact] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Exit_Command90_Click:
Exit Sub
Err_Command90_Click:
MsgBox Err.Description
Resume Exit_Command90_Click
End Sub