Link to home
Start Free TrialLog in
Avatar of junaidIT
junaidITFlag for United Arab Emirates

asked on

pass user inputbox value to filter records using query and display on a form in access 2007

i have a form that is having fields from a query. what i am looking for is , to have user click on a button to enter a string, accept that as the criteria and filter and display only those records on the form.

I am using access 2007.
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Assuming your Form is based on the records you wish to filter:

Dim sInput As String

sInput = InputBox("Enter your value: ")

If Len(sInput) > 0 Then
  Me.Filter = "SomeField='" & sInput & "'"
  Me.FilterOn = True
End If

This assumes that you're filtering on a Text value.

If filtering on a Numeric:
  Me.Filter = "SomeField=" & sInput

If filtering on a Date:
  Me.Filter = "SomeField=#" & sInput & "#"

Avatar of junaidIT

ASKER

apologies,

totally new to the programming  or even for that matter any sort of coding

may be if i tell the scenario, that will make it more clear.

i have a table wth one of the fields called dealcode(defined as plain text)

now what i want is , when  a user clicks on a command button which is on a separate form, , he gets a input box , where he could enter the text(which is equivalent or similar to the field dealcode) and this gets passed onto a query as a criteria, where all the fields from the query are displayed on the form)

thanks
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi,

tried your code. however what is happening is that , an input box comes twice, first like a normal input box, second as if there is a parameter query running. and then it displays all the records that are there and doesnt filter anything.

the record source for the form is a query that pulls data out of the main table.
You must make certain that you have correctly spelled everything, including the name of the Field in your query.

Is "dealcode" a TEXT or NUMERIC field in the table?

If you open your query directly, do you get a prompt?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
issue fixed. thanks all for the inputs