Hi everyone,
I've put together bits of things that I've been working on learning from this site and created a form that almost works.
The user selects a location, or "---All Locations---" from a combo box (used AddAllToList to add All). This is supposed to update two subforms on the form. I used the code from Mile's sample db located here and modified it to get:
My problem is that, when I open the form, if the FIRST selection I make is "---All Locations---" I get the data for all locations, no matter how many times I change my combo box. If the FIRST selection I make is out of the rest of the list, the subforms will change when I make a different selection, and give me no data when I select "---All Locations---". I think this means that my code is not running when I update the combo box, but I can't figure out why.
Any help anyone can give me to fix this problem would be greatly appreciated.
Thanks,
~Nuke~
I've put together bits of things that I've been working on learning from this site and created a form that almost works.
The user selects a location, or "---All Locations---" from a combo box (used AddAllToList to add All). This is supposed to update two subforms on the form. I used the code from Mile's sample db located here and modified it to get:
Code:
Private Sub Station_AfterUpdate()
On Error GoTo Err_Station_AfterUpdate
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim var As Variant
Set db = CurrentDb
If Me.Station = "---All Locations---" Then
strSQL = "{mySQL - no filter for location}"
Else
strSQL = "{mySQL - filtered for location}"
End If
On Error Resume Next
db.QueryDefs.Delete "qryStationDose"
On Error GoTo Err_Station_AfterUpdate
Set qdf = db.CreateQueryDef("qryStationDose", strSQL)
Me.Subform1.Requery
Me.Subform2.Requery
Exit_Station_AfterUpdate:
Set qdf = Nothing
Set db = Nothing
Exit Sub
Err_Station_AfterUpdate:
MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
Resume Exit_Station_AfterUpdate
End Sub
My problem is that, when I open the form, if the FIRST selection I make is "---All Locations---" I get the data for all locations, no matter how many times I change my combo box. If the FIRST selection I make is out of the rest of the list, the subforms will change when I make a different selection, and give me no data when I select "---All Locations---". I think this means that my code is not running when I update the combo box, but I can't figure out why.
Any help anyone can give me to fix this problem would be greatly appreciated.
Thanks,
~Nuke~