I have a form with a search feature on it. It searches by a field called Code. Codes are in the form D****, the stars are all numbers. So D0240, D9820, D6513 are all valid codes. Instead of having to type the D in every time, I have the search feature so you can just type in the 4 digit number and in the code it appends the D and pulls up the correct record.
Then I have a button on the form to open another form where you can associate rules to the code. It opens the Rules form with the correct code pulled up based on what Code you were on when you clicked the button on the Codes form. This works fine if you open the form and don't use the search feature and just scroll the records with the scroll on the bottom. Also, I had the search before where you had to type the "D" and it worked fine.
Now when I changed it to where the "D" was appended in the code, that button no longer works. If I open the codes form and do a search to pull up a Code, then click the Rules button for that code, it doesn't open the rules form at all, it just goes to a blank record on the Codes form. I can't understand why it's doing that. Here's the code for the Rules button.
Then in my search I have this...
Anyone have any idea why this happens?
Then I have a button on the form to open another form where you can associate rules to the code. It opens the Rules form with the correct code pulled up based on what Code you were on when you clicked the button on the Codes form. This works fine if you open the form and don't use the search feature and just scroll the records with the scroll on the bottom. Also, I had the search before where you had to type the "D" and it worked fine.
Now when I changed it to where the "D" was appended in the code, that button no longer works. If I open the codes form and do a search to pull up a Code, then click the Rules button for that code, it doesn't open the rules form at all, it just goes to a blank record on the Codes form. I can't understand why it's doing that. Here's the code for the Rules button.
Code:
Private Sub Rules22_Click()
On Error GoTo Err_Rules22_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Code_Rules"
stLinkCriteria = "[Code]=" & "'" & Me![CodeNumber] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Rules22_Click:
Exit Sub
Err_Rules22_Click:
MsgBox Err.Description
Resume Exit_Rules22_Click
End Sub
Then in my search I have this...
Code:
Private Sub FindButton_Click()
If IsNull(Me.FindCode) Then
MsgBox "Enter a Code"
Else
Call CodeSearch(Me.FindCode.Value)
End If
End Sub
Function CodeSearch(CodeNmbr As String)
Dim answer As String
answer = "D" & CodeNmbr
If answer <> "" Then
DoCmd.OpenForm "Codes", , , "[Code]='" & answer & "' "
End If
[Forms]![Codes].FindCode.Value = ""
End Function
Anyone have any idea why this happens?