Eric the Viking
Registered User.
- Local time
- Today, 06:04
- Joined
- Sep 20, 2012
- Messages
- 70
I have some code for a button on click event to open a form and select the record which corresponds to a value in an unbound text box. The code is:
Private Sub Command25_Click()
On Error GoTo Err_Command25_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmOpenPatientRecord"
If Len(Me![Text27] = 10) Then
stLinkCriteria = "[NHSnumber]=" & "'" & Me![Text27] & "'"
ElseIf Len(Me![Text27] < 10) Then
stLinkCriteria = "[PatientNumber]=" & "'" & Me![Text27] & "'"
End If
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Command25_Click:
Exit Sub
Err_Command25_Click:
MsgBox Err.Description
Resume Exit_Command25_Click
End Sub
This works fine when I put in a 10 digit NHS number but opens a blank record when I enter a four digit or six character/digit PatientNumber. Both patient number and NHS number are text fields in the underlying table.
I would really appreciate advice on where I am going wrong.
Many thanks in advance.
Eric
Private Sub Command25_Click()
On Error GoTo Err_Command25_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmOpenPatientRecord"
If Len(Me![Text27] = 10) Then
stLinkCriteria = "[NHSnumber]=" & "'" & Me![Text27] & "'"
ElseIf Len(Me![Text27] < 10) Then
stLinkCriteria = "[PatientNumber]=" & "'" & Me![Text27] & "'"
End If
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Command25_Click:
Exit Sub
Err_Command25_Click:
MsgBox Err.Description
Resume Exit_Command25_Click
End Sub
This works fine when I put in a 10 digit NHS number but opens a blank record when I enter a four digit or six character/digit PatientNumber. Both patient number and NHS number are text fields in the underlying table.
I would really appreciate advice on where I am going wrong.
Many thanks in advance.
Eric