Placing result of Input Box into a query/report

M

Michael Hinde

Can anyone please tell me how to place the result of an
Input Box into a query (as a selection parameter)?

I have the following code set up to check that the
information (ATM Prefix) entered by the user does exist
within the database but am at a loss as to how I can then
run a query without the user having to input the prefix
again. (obviously making the whole code redundant!)

Any help much appreciated.
Michael


*************************************************
Public Sub Box11_Click()
On Error GoTo Err_Box11_Click

Dim db As Database
Dim rec As Recordset
Dim strSQL As String
Dim strSQL2 As String
Dim strAns As String

strAns = InputBox("Please enter the ATM
Prefix... ", "Single Prefix Report")

If strAns <> "" Then
Set db = CurrentDb()

strSQL = "select * from tblAtmDetails where
ATM_Prefix = '" & strAns & "'"
Set rec = db.OpenRecordset(strSQL)
If rec.RecordCount = 0 Then
MsgBox "This ATM Prefix has no available
contribution stats"
rec.Close
Else

' Feed [strAns] into a (large) query

' Run the query/report now

End If
End If
 
J

Jen

Hi,

Your sql statement needs a ; at the end.

strSQL = "select * from tblAtmDetails where
ATM_Prefix = '" & strAns & "';"

and Dim your recordset object as a DAO.Recordset

Dim rec As DAO.Recordset

Regards,
Jen
 

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