Syntax Error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form where a user can enter the date so that a list of invoices
meeting that date will be printed. My code looks like this:

Dim strWhere As String
strWhere = "'[dteInvoiceDate]=" & Me.txtSpecificDate '"
DoCmd.OpenReport "rptInvoiceListByDate", acPreview, , strWhere

However I get a Syntax error in string in expression. Is there something
wrong with the code? Thanks.
ck
 
Yes, two things: Firstly, you're feeding a string value to the OpenReport
method, when it expects an SQL clause. Remove the single quotes from the
clause. Secondly, you should specify # to indicate a literal date.

strWhere = "[dteInvoiceDate] = #" & Me.txtSpecificDate & "#"

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Thanks, Graham...it worked!. Well, it gets more complicated. I also have a
field to allow a user to enter the month only. How do I get the report to
display only for the month entered?
ck

Graham R Seach said:
Yes, two things: Firstly, you're feeding a string value to the OpenReport
method, when it expects an SQL clause. Remove the single quotes from the
clause. Secondly, you should specify # to indicate a literal date.

strWhere = "[dteInvoiceDate] = #" & Me.txtSpecificDate & "#"

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

CK said:
I have a form where a user can enter the date so that a list of invoices
meeting that date will be printed. My code looks like this:

Dim strWhere As String
strWhere = "'[dteInvoiceDate]=" & Me.txtSpecificDate '"
DoCmd.OpenReport "rptInvoiceListByDate", acPreview, , strWhere

However I get a Syntax error in string in expression. Is there something
wrong with the code? Thanks.
ck
 
CK,

strWhere = "Month([dteInvoiceDate]) = " & Me.txtMonthNumber

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

CK said:
Thanks, Graham...it worked!. Well, it gets more complicated. I also have a
field to allow a user to enter the month only. How do I get the report to
display only for the month entered?
ck

Graham R Seach said:
Yes, two things: Firstly, you're feeding a string value to the OpenReport
method, when it expects an SQL clause. Remove the single quotes from the
clause. Secondly, you should specify # to indicate a literal date.

strWhere = "[dteInvoiceDate] = #" & Me.txtSpecificDate & "#"

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

CK said:
I have a form where a user can enter the date so that a list of invoices
meeting that date will be printed. My code looks like this:

Dim strWhere As String
strWhere = "'[dteInvoiceDate]=" & Me.txtSpecificDate '"
DoCmd.OpenReport "rptInvoiceListByDate", acPreview, , strWhere

However I get a Syntax error in string in expression. Is there
something
wrong with the code? Thanks.
ck
 
Back
Top