Problem passing combo box values in form to query (1 Viewer)

leladavis

New member
Local time
Today, 04:02
Joined
Jul 14, 2011
Messages
7
I am new to this forum so I apologize if I am posting this in the wrong place.

I am using a form with 2 combo boxes for the user to enter a start date and end date. I want this to be passed to a query. The form also contains a button to run a report from that query.

My issue is I enter the dates into the combo boxes and try to run my report using the button but I am still prompted to input the start and end dates. Can someone please help?

The names for for the combo boxes are "QtrStartDate" and "QtrEndDate".

Here is the code I have so far:
Code:
'Set date range for report based off form selection
Dim StrWhere As String

StrWhere = "[QtrStartDate]= " & Me.QtrStartDate & "AND [QtrEndDate]= " & Me.QtrEndDate

' Open the report
DoCmd.OpenReport "rpt_2011Q1_ReportingData", acPreview, , StrWhere
 
Last edited:

MarkK

bit cruncher
Local time
Today, 02:02
Joined
Mar 17, 2004
Messages
8,199
To indicate to the system that data is a date you want to delimit with "#" characters, so try...
Code:
StrWhere = "[QtrStartDate]= #" & Me.QtrStartDate & "# AND [QtrEndDate] = #" & Me.QtrEndDate & "#"
 

leladavis

New member
Local time
Today, 04:02
Joined
Jul 14, 2011
Messages
7
Thanks for the fast reply! I tried your suggestions and still am prompted for the dates.
 

leladavis

New member
Local time
Today, 04:02
Joined
Jul 14, 2011
Messages
7
Do you or anyone else have any other suggestions on what I am doing wrong? I appreciate any help I can get.
 

MarkK

bit cruncher
Local time
Today, 02:02
Joined
Mar 17, 2004
Messages
8,199
Then probably the named field doesn't exist in your table, for instance, if I have a table with the following structure...
tTable
FieldID
Field1
Field2
... and I write and run a query ...
Code:
SELECT * FROM tTable WHERE [Field3] = 'SomeValue'
... then I will be prompted for the value of [Field3]. The query parser assumes that anything it can't otherwise identify is parameter.
Cheers,
Mark
 

leladavis

New member
Local time
Today, 04:02
Joined
Jul 14, 2011
Messages
7
I believe I have corrected my previous issue but am receiving the following error:

"Syntax Error (missing operator) in query expression '[FNOL Date]= Between #3/1/2011# AND #6/30/2011#'

Here is my code:
Code:
'Set date range for report based off form selection
StrWhere = "[FNOL Date]= Between #" & Me.StartDate & "# AND #" & Me.EndDate & "#"


' Open the report
DoCmd.OpenReport "rpt_2011Q1_ReportingData", acPreview, , StrWhere

Any ideas why I am receiving this error?
 

spikepl

Eledittingent Beliped
Local time
Today, 11:02
Joined
Nov 3, 2010
Messages
6,142
Code:
StrWhere = "[FNOL Date][COLOR=Red]=[/COLOR] Between #" & Me.StartDate & "# AND #" & Me.EndDate & "#"
 

Users who are viewing this thread

Top Bottom