VBA WHERE clause in VBA parameter query

  • Thread starter charles.kendricks
  • Start date
C

charles.kendricks

I have a form that is populated using this parameter query:

SELECT tblCustomer.*
FROM tblCustomer
WHERE (((tblCustomer.LName)=[Please Enter Last Name]));

I want to use VBA to accomplish the same thing...I tried:

Dim strLName As String
strLName = InputBox("What is the last name", "Name?")
Me.CustCriteria = "Search for customers with the last name of " &
Me.LName
DoCmd.OpenForm "frmCustDataInput", , , "(((tblCustomer.LName)=" &
strLName & "))"

I've tried several different derivitives of the WHERE clause with no
success thus far...What am I doing wrong?
 
R

Rick Brandt

I have a form that is populated using this parameter query:

SELECT tblCustomer.*
FROM tblCustomer
WHERE (((tblCustomer.LName)=[Please Enter Last Name]));

I want to use VBA to accomplish the same thing...I tried:

Dim strLName As String
strLName = InputBox("What is the last name", "Name?")
Me.CustCriteria = "Search for customers with the last name of " &
Me.LName
DoCmd.OpenForm "frmCustDataInput", , , "(((tblCustomer.LName)=" &
strLName & "))"

I've tried several different derivitives of the WHERE clause with no
success thus far...What am I doing wrong?

The value is a string so it needs to be quoted.

"LName = '" & strLName & "'"
 
D

Douglas J. Steele

Rick Brandt said:
I have a form that is populated using this parameter query:

SELECT tblCustomer.*
FROM tblCustomer
WHERE (((tblCustomer.LName)=[Please Enter Last Name]));

I want to use VBA to accomplish the same thing...I tried:

Dim strLName As String
strLName = InputBox("What is the last name", "Name?")
Me.CustCriteria = "Search for customers with the last name of " &
Me.LName
DoCmd.OpenForm "frmCustDataInput", , , "(((tblCustomer.LName)=" &
strLName & "))"

I've tried several different derivitives of the WHERE clause with no
success thus far...What am I doing wrong?

The value is a string so it needs to be quoted.

"LName = '" & strLName & "'"

Because it's possible that the name might include an apostrophe (O'Reilly),
it's probably better to use:

"LName = """ & strLName & """"

or

"LName = " & Chr$(34) & strLName & Chr$(34)
 
D

David F Cox

It is not great GUI, but would not the original SQL work the same way as it
did?

(I am too pressed to try it myself right now)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top