Hi there,
I am having a heck of a time attempting to open a form and filter it automatically based on a date derived from a control on another form.
I am using the DoCmd.OpenForm method and applying and applying criteria to the "WhereCondition".
Initially the code looked like this and worked just fine:
Private Sub GoToPlantSpeciesForm_Click()
Dim stDocName As String
Dim stSiteID As Date
Dim stLinkCriteria As String
stDocName = "PlantSpecies"
stSiteID = Me.SiteID_Header.Value
stLinkCriteria = "[Site_ID] = " & " '" & stSiteID & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit, acDialog
Exit Sub
As you can see, it is taking the ID value from a control on a main form and using it to filter out records on the "PlantSpecies" form.
However, it was determined that we should also filter by a date field common to both tables:
Private Sub GoToPlantSpeciesForm_Click()
Dim stDocName As String
Dim stSiteID As Date
Dim dtSurveyDate As Date
Dim stLinkCriteria As String
stDocName = "PlantSpecies"
stSiteID = Me.SiteID_Header.Value
dtSurveyDate = Me.Survey_Date.Value
stLinkCriteria = "[Site_ID] = " & " '" & stSiteID & "' And [Date] = #" _
& dtSurveyDate & "#"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit, acDialog
Exit Sub
Now the filter returns nothing.
If I set the date portion of the Where condition to a specific date it works fine, ie:
stLinkCriteria = "[Site_ID] = " & " '" & stSiteID & "' And [Date] = #12/6/2010#"
I'm sure it is some minor syntax thing. I'm not receiving any error message, mind you. The form opens with a filter applied, but showing no records as a result of the filter. Again, this only occurs when I assign a date to a variable and then use that date variable in the where condition.
Help! Please! If I had any hair to tear out, I would be doing so!
thanks!
I am having a heck of a time attempting to open a form and filter it automatically based on a date derived from a control on another form.
I am using the DoCmd.OpenForm method and applying and applying criteria to the "WhereCondition".
Initially the code looked like this and worked just fine:
Private Sub GoToPlantSpeciesForm_Click()
Dim stDocName As String
Dim stSiteID As Date
Dim stLinkCriteria As String
stDocName = "PlantSpecies"
stSiteID = Me.SiteID_Header.Value
stLinkCriteria = "[Site_ID] = " & " '" & stSiteID & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit, acDialog
Exit Sub
As you can see, it is taking the ID value from a control on a main form and using it to filter out records on the "PlantSpecies" form.
However, it was determined that we should also filter by a date field common to both tables:
Private Sub GoToPlantSpeciesForm_Click()
Dim stDocName As String
Dim stSiteID As Date
Dim dtSurveyDate As Date
Dim stLinkCriteria As String
stDocName = "PlantSpecies"
stSiteID = Me.SiteID_Header.Value
dtSurveyDate = Me.Survey_Date.Value
stLinkCriteria = "[Site_ID] = " & " '" & stSiteID & "' And [Date] = #" _
& dtSurveyDate & "#"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit, acDialog
Exit Sub
Now the filter returns nothing.
If I set the date portion of the Where condition to a specific date it works fine, ie:
stLinkCriteria = "[Site_ID] = " & " '" & stSiteID & "' And [Date] = #12/6/2010#"
I'm sure it is some minor syntax thing. I'm not receiving any error message, mind you. The form opens with a filter applied, but showing no records as a result of the filter. Again, this only occurs when I assign a date to a variable and then use that date variable in the where condition.
Help! Please! If I had any hair to tear out, I would be doing so!
thanks!