By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,504 Members | 2,606 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,504 IT Pros & Developers. It's quick & easy.

Using Like operator with form Parameter

P: 2
I am trying to write write code to get account numbers such as "10.1260.410180.121 X" or "10.1260.10180.276P X". The form has a text field the user keys in either "X" or "P X". I have been trying to find the code for the like statement and for the life of me can't find it. So far I have:

Expand|Select|Wrap|Line Numbers
  1.     mysql = "SELECT * from InvoiceTable " & _
  2.             " WHERE (InvoiceTable.InvoicePrintDate1 Is Null)" & _
  3.             " AND (InvoiceTable.AccountNumber LIKE acctltr)" & _
  4.             " AND (datevalue([InvoiceTable.InvoiceDate]) >= #" & dtefrom & "#)" & _
  5.             " AND (datevalue([InvoiceTable.InvoiceDate]) <= #" & dteto & "#)"
  6.  
  7.     Me.Form.RecordSource = mysql
  8.  
  9.     If Me.Form.Recordset.RecordCount > 0 Then
  10.         DoCmd.OpenReport "rptInvoiceSumReport", acViewPreview, , _
  11.                          "(    (InvoiceTable.InvoicePrintDate1 is  Null)" & _
  12.                          " AND (InvoiceTable.AccountNumber LIKE acctltr)" & _
  13.                          " AND (Datevalue([InvoiceTable.InvoiceDate]) >= #" & dtefrom & "#)" & _
  14.                          " AND (datevalue([InvoiceTable.InvoiceDate]) <= #" & dteto & "#))"
  15.     End If
I know I have to enter a % sign in there somewhere.

Thanks for any help given! :)
Dec 5 '13 #1

✓ answered by ADezii

If you are reading the Criteria (X or P X) from a Text Box on a Form, the Syntax would be:
Expand|Select|Wrap|Line Numbers
  1. WHERE myTable.Field1 Like '*" & Me!txtCriteria & "'"

Share this Question
Share on Google+
7 Replies


NeoPa
Expert Mod 15k+
P: 31,186
Are you sure you intended to ask this question in the Access forum?

NB. You don't include anything which ndicates what you have used in acctltr for use in your LIKE statement.
Dec 5 '13 #2

zmbd
Expert Mod 5K+
P: 5,287
1) Using the Like operator and wildcard characters in string comparisons (ACC2007/2010)

2) In agreement with Neopa: 'acctltr' ???
It would be helpful to understand how you are setting/refencing this value.
Dec 5 '13 #3

ADezii
Expert 5K+
P: 8,599
If you are reading the Criteria (X or P X) from a Text Box on a Form, the Syntax would be:
Expand|Select|Wrap|Line Numbers
  1. WHERE myTable.Field1 Like '*" & Me!txtCriteria & "'"
Dec 6 '13 #4

P: 2
Thank you so much ADezii! I got it working! :)
Dec 6 '13 #5

ADezii
Expert 5K+
P: 8,599
You are quite welcome, glad it worked out.
Dec 6 '13 #6

NeoPa
Expert Mod 15k+
P: 31,186
2nd Neopa: 'acctltr' ???
It's a reference in the code of the OP found at lines #3 & #12.
Dec 7 '13 #7

zmbd
Expert Mod 5K+
P: 5,287
2nd as in "I 2nd the motion"
(^-^)
Dec 7 '13 #8

Post your reply

Sign in to post your reply or Sign up for a free account.