Access Table Filtered based upon Excel User Input

JWalcott

New Member
Joined
Jan 25, 2003
Messages
34
I recorded a macro Importing External Data from Access and specifying in Microsoft Query that I only want employees that work for Client '0001'. No problem there. But when I try to do the same query where the user types in the Client Number = '0001', the input is stored publicly as a variant data type ClientNum = '0001', the sub procedure obtaining the data from Access returns only the column headings, no data!!
Hoping this is just a data type misunderstanding, any help would be appreciated. Sample of code obtaining results followed by the code returning no data.

"SELECT Employees.Participant, Employees.SocialSecurityNumber, Employees.FirstName, Employees.LastName, Employees.Title, Employees.Birthdate, Employees.StartDate, Employees.Salary, Employees.`HCE/Key`," _
, _
" Employees.ClientNumber" & Chr(13) & "" & Chr(10) & "FROM `C:\My Documents\db1`.Employees Employees" & Chr(13) & "" & Chr(10) & "WHERE (Employees.ClientNumber='0001')" & Chr(13) & "" & Chr(10) & "ORDER BY Employees.`HCE/Key`" _
)

' NO RESULTS CODE
"SELECT Employees.Participant, Employees.SocialSecurityNumber, Employees.FirstName, Employees.LastName, Employees.Title, Employees.Birthdate, Employees.StartDate, Employees.Salary, Employees.`HCE/Key`," _
, _
" Employees.ClientNumber" & Chr(13) & "" & Chr(10) & "FROM `C:\My Documents\db1`.Employees Employees" & Chr(13) & "" & Chr(10) & "WHERE (Employees.ClientNumber='ClientNum')" & Chr(13) & "" & Chr(10) & "ORDER BY Employees.`HCE/Key`" _
)

JW
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You can set up a parameter query by putting a question in square brackets in the criteria of the field (MS Query Design grid).

Replace your criteria "ClientNum" with

[Enter Client Code]

Would be a Question mark in SQL

..."WHERE (Employees.ClientNumber= ? )" ...

Works just like Access

Try this instead of the Input box you may be using, When you run the Macro the user will be prompted .
 
Upvote 0

Forum statistics

Threads
1,221,567
Messages
6,160,541
Members
451,655
Latest member
rugubara

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top