Clifton Hughes
asked on
Opening forms with an input box
I am trying to open a Form in Access with an input box, but I want to make sure the record exists in the table.
Private Sub Command6_Click()
On Error GoTo Err_ExistingExamID
Dim strInput As String
Dim recordCount As Integer
Dim tryAgain As Integer
'enter loop
Do
'get input
strInput = InputBox("Please enter a valid Exam ID")
'check input
If Len(strInput) <> 0 Then
'look for Booking reference number in tblHABookings
recordCount = Nz(DCount("*", "tblExams", "[ExID] = '" & strInput & "'"), 0)
If recordCount <> 0 Then 'booking reference was found
tryAgain = vbNo
'open Amend form
DoCmd.OpenForm "frmExaminations", , , "ExID= '" & strInput & "'"
Else ' booking reference was NOT found
'prompt user again
tryAgain = MsgBox("Exam ID '" & strInput & "' was not found. Try again?", vbYesNo)
End If
Else
tryAgain = vbNo
End If
Loop Until tryAgain = vbNo
Exit_ExistingExamID:
Exit Sub
Err_ExistingExamID:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
'MsgBox Err.Description
Resume Exit_ExistingExamID
End Sub
What difficulty are you having?
ASKER
When I execute the command, I get the Error telling me the data type mismatch in criteria expression. I should note the ExID is an autonumber.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks arana!! I knew if was something simple I was overlooking.