I've just started using vba with Access and am still trying to get my head around using SQL within a database I am creating.
Basically, this bit of code works fine until I try to get it to be a bit more flexible. The aim of it is to display a graph showing two axes of results versus a single month of the year - the SQL statement creates a table which is used by a query within the form 'Graph' to show a graph. This bit works and creates the table with the data I require:
Private Sub Command56_Click()
Dim dbs As Database, rst As Recordset
Dim varposition As Variant
DoCmd.SetWarnings (False)
If Combo52 = "-SELECT A MONTH-" Then
Message ("You have not specified a month. Click OK to return to select a month."
Else
DoCmd.RunSQL "SELECT Date, Nitrate, SSVI INTO GData FROM [Daily Water Treatment Plant Readings] WHERE Date Between #01/05/01# And #31/05/01;"
End If
DoCmd.OpenForm "Graph"
End Sub
But when I make a few changes to try and get the date to be user specified through a combobox, the code doesn't seem to work:
Private Sub Command56_Click()
Dim dbs As Database, rst As Recordset
Dim varposition As Variant
Dim d1 As String
Dim d2 As String
If Combo52 = "January" Then
d1 = "#01/01/01#" And d2 = "#31/01/01#"
End If
DoCmd.SetWarnings (False)
If Combo52 = "-SELECT A MONTH-" Then
Message ("You have not specified a month. Click OK to return to select a month."
Else
DoCmd.RunSQL "SELECT Date, Nitrate, SSVI INTO GData FROM [Daily Water Treatment Plant Readings] WHERE Date Between d1 And d2;"
End If
DoCmd.OpenForm "Graph"
End Sub
I know it's probably something very simple, but can anyone point me in the right direction?
Thanks for your time.
Basically, this bit of code works fine until I try to get it to be a bit more flexible. The aim of it is to display a graph showing two axes of results versus a single month of the year - the SQL statement creates a table which is used by a query within the form 'Graph' to show a graph. This bit works and creates the table with the data I require:
Private Sub Command56_Click()
Dim dbs As Database, rst As Recordset
Dim varposition As Variant
DoCmd.SetWarnings (False)
If Combo52 = "-SELECT A MONTH-" Then
Message ("You have not specified a month. Click OK to return to select a month."
Else
DoCmd.RunSQL "SELECT Date, Nitrate, SSVI INTO GData FROM [Daily Water Treatment Plant Readings] WHERE Date Between #01/05/01# And #31/05/01;"
End If
DoCmd.OpenForm "Graph"
End Sub
But when I make a few changes to try and get the date to be user specified through a combobox, the code doesn't seem to work:
Private Sub Command56_Click()
Dim dbs As Database, rst As Recordset
Dim varposition As Variant
Dim d1 As String
Dim d2 As String
If Combo52 = "January" Then
d1 = "#01/01/01#" And d2 = "#31/01/01#"
End If
DoCmd.SetWarnings (False)
If Combo52 = "-SELECT A MONTH-" Then
Message ("You have not specified a month. Click OK to return to select a month."
Else
DoCmd.RunSQL "SELECT Date, Nitrate, SSVI INTO GData FROM [Daily Water Treatment Plant Readings] WHERE Date Between d1 And d2;"
End If
DoCmd.OpenForm "Graph"
End Sub
I know it's probably something very simple, but can anyone point me in the right direction?
Thanks for your time.