Hello All,
I am relatively new to Access and definitely new to vb, and I think I've bitten off more than I can chew.
I have created a pop-up search form with the search criteria being one unbound field. When I populate the field and click search I want it to search the records and if there is a matching record, I want it to open the data entry form with the complete record showing and available to view/edit/delete. If there is no matching record, I want a message box to appear stating that a record was not found and when you click 'ok' it opens a blank data entry form to complete a new record. I also want it to automatically close the search pop-up form.
The following works great... except that the MsgBox pops up even if the record was found. Any help would be very much appreciated. Thank you!
Private Sub Search_Click()
On Error GoTo Err_Search_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "MgrData"
'get current MgrID
tmp = Me.MgrID
Me.MgrID.Enabled = False
'check if the MgrID was found
If (tmp = Me.MgrID) And (Me.MgrID <> stDocName) Then
MsgBox "A record does not currently exist for this Manager ID. You may enter a new record, or click CANCEL to return to the main menu"
stLinkCriteria = "[MgrID]=" & "'" & Me![MgrID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
stLinkCriteria = "[MgrID]=" & "'" & Me![MgrID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
DoCmd.Close acForm, Me.Name
Exit_Search2_Click:
Exit Sub
Err_Search2_Click:
MsgBox Err.Description
Resume Exit_Search2_Click
End Sub
I am relatively new to Access and definitely new to vb, and I think I've bitten off more than I can chew.
I have created a pop-up search form with the search criteria being one unbound field. When I populate the field and click search I want it to search the records and if there is a matching record, I want it to open the data entry form with the complete record showing and available to view/edit/delete. If there is no matching record, I want a message box to appear stating that a record was not found and when you click 'ok' it opens a blank data entry form to complete a new record. I also want it to automatically close the search pop-up form.
The following works great... except that the MsgBox pops up even if the record was found. Any help would be very much appreciated. Thank you!
Private Sub Search_Click()
On Error GoTo Err_Search_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "MgrData"
'get current MgrID
tmp = Me.MgrID
Me.MgrID.Enabled = False
'check if the MgrID was found
If (tmp = Me.MgrID) And (Me.MgrID <> stDocName) Then
MsgBox "A record does not currently exist for this Manager ID. You may enter a new record, or click CANCEL to return to the main menu"
stLinkCriteria = "[MgrID]=" & "'" & Me![MgrID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
stLinkCriteria = "[MgrID]=" & "'" & Me![MgrID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
DoCmd.Close acForm, Me.Name
Exit_Search2_Click:
Exit Sub
Err_Search2_Click:
MsgBox Err.Description
Resume Exit_Search2_Click
End Sub