BlueJacket
Registered User.
- Local time
- Today, 10:42
- Joined
- Jan 11, 2017
- Messages
- 90
I feel like I got this working, but I also feel like I went on a roundabout way to do it, using more code than I need to. Currently I have cboCounty updating and filtering cboJudgeName when a county is selected. This part works fine. For reference, here's that code:
The problem is, that filter stays. Without further code, when I go to a different record that has a different county, cboJudgeName appears blank because the judge linked to that recorded isn't linked to the previously selected county.
So my solution is to reset the query whenever the GoToRecord search is used to select a different property.
I also feel that I would have to use the same SQL code on cboCounty's After Update event on the form's OnLoad event to have all my bases covered.
This all gets the job done, but it seems like a lot. Is this the best way to about doing this?
Thanks in advance.
Code:
Public Sub cboCounty_AfterUpdate()
If gEnableErrorHandling Then On Error GoTo Errhandle
'Limits the selection of Judges based off what the user picks in the County combobox
Dim stSQL As String
stSQL = ""
stSQL = stSQL & "SELECT "
stSQL = stSQL & " tblJudges.JudgeID "
stSQL = stSQL & ", tblJudge_County.CountyID "
stSQL = stSQL & ", tblJudges.JudgeName "
stSQL = stSQL & "FROM tblJudges "
stSQL = stSQL & "INNER JOIN tblJudge_County "
stSQL = stSQL & "ON tblJudge_County.JudgeID = tblJudges.JudgeID "
stSQL = stSQL & "WHERE tblJudge_County.CountyID = '" & Me![cboCounty].Column(0) & "'"
Me![cboJudgeName].RowSource = stSQL
'Me![cboJudgeName].SetFocus
'Me![cboJudgeName].Dropdown
Exit Sub
Errhandle:
MsgBox "Error " & Err.Number & ": " & Err.Description & _
vbCrLf & "Please make a note of this error and when it occured." & _
vbCrLf & " " & FormatDateTime(Now(), vbGeneralDate)
End Sub
The problem is, that filter stays. Without further code, when I go to a different record that has a different county, cboJudgeName appears blank because the judge linked to that recorded isn't linked to the previously selected county.
So my solution is to reset the query whenever the GoToRecord search is used to select a different property.
Code:
Private Sub cboGoToRecord_AfterUpdate()
'Searches properties based off the info entered in the GoToRecord searchbox
If gEnableErrorHandling Then On Error GoTo Errhandle
Dim rst As Object
Dim stSQL As String
stSQL = ""
stSQL = stSQL & "SELECT "
stSQL = stSQL & " tblJudges.JudgeID, "
stSQL = stSQL & " tblJudge_County.CountyID, "
stSQL = stSQL & " tblJudges.JudgeName "
stSQL = stSQL & "FROM tblJudges "
stSQL = stSQL & "INNER JOIN tblJudge_County "
stSQL = stSQL & "ON tblJudges.JudgeID = tblJudge_County.JudgeID;"
[COLOR="Blue"]Difference: No WHERE clause. Also realized how I order my code on a subroutine matters.[/COLOR]
Me![cboJudgeName].RowSource = stSQL
Set rst = Me.RecordsetClone
rst.FindFirst "[PropertyID]=" & Me.cboGoToRecord.Value
Me.Bookmark = rst.Bookmark
Exit Sub
Errhandle:
MsgBox "Error " & Err.Number & ": " & Err.Description & _
vbCrLf & "Please make a note of this error and when it occured." & _
vbCrLf & " " & FormatDateTime(Now(), vbGeneralDate)
End Sub
I also feel that I would have to use the same SQL code on cboCounty's After Update event on the form's OnLoad event to have all my bases covered.
This all gets the job done, but it seems like a lot. Is this the best way to about doing this?
Thanks in advance.