tksy
tksy

Reputation: 3529

Áccess VBA:How to get input in forms and use them in queries

HI

I have a form with a few buttons. Each button runs a few lines of code.the code have queries also in them like "select * from table where number =6"

now if i want to give the number as a input in the form, how do i go about it.

Upvotes: 2

Views: 2934

Answers (1)

Philippe Grondier
Philippe Grondier

Reputation: 11148

  1. Add an unbound text control close to your button.
  2. Update your button code to generate the query string as :

    "SELECT * FROM myTable WHERE myNumber =" & me.controls("myControlName").value

  3. You might feel the need to make sure that the "myControlName" control allows only numbers/do not accept null, or treat all cases in your procedure


myQuery = "SELECT * FROM myTable"
If Isnull(me.controls("myControlName").value) then
Else
    If isnumeric(me.controls("myControlName").value) then 
        myQuery = myQuery & " WHERE myNumber =" & me.controls("myControlName").value     
    Else 
        msgBox me.controls("myControlName").value & " is not accepted" 
        Exit function 
    Endif
Endif

Upvotes: 3

Related Questions