How to code a query with a prompt for entering a parameter value? Really thanks.

X

xpengi

Hi Guys,

In my application system design, user enters the value with promp
message window,
then generate report based on this value of the query.

I code it as following but not work:
...
Dim strSQL As String

strSQL = "SELECT CITY, COUNT(*) AS [NUMBER OF STUDENTS] FROM " _
& TABLE_NAME & " WHERE CITY = [Enter CITY
GROUP BY CITY;"

Me.RecordSource = strSQL
...

if as saving query, it will works, but in code not. why? how to d
that?
should i use inputbox instead?

Thanks a lot!
 
K

Ken Snell [MVP]

You could use InputBox, yes:

strSQL = "SELECT CITY, COUNT(*) AS [NUMBER OF STUDENTS] FROM " _
& TABLE_NAME & " WHERE CITY = '" & _
InputBox("Enter CITY:") & "' GROUP BY CITY;"
 

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