Query/command button

  • Thread starter Thread starter Cyp
  • Start date Start date
C

Cyp

hi

if i have a table with one of the fields being "Department" which has
range of numbers from 1 to 10

how can i have 10 command buttons in a form that each filters
different department number. ( so a new form opens with the records o
only that department number)

i only want to use 1 query and i dont want to prompt the user with th
criteria "Enter Deparment Number:"


thn
 
Instead of using command buttons use a combobox or listbox and filte
your query based on the response received from the control.

You fill the list for the control with the contents of your departmen
table. This way if your list grows your ability to respon
automatically grows with it
 
thnx for the response.. but i need them to be 10 different comman
buttons.

im this case do i need to create 10 different queries and 10 dif
forms
 
The answer is no. If you use the onclick event you can open a for
based upon the data of a table or query that includes all 1
departments, but use the where criteria of the docmd.openform method t
limit the data to just the department you want based upon which butto
was clicked
 
If you have a button on a form, in the properties (under events tab) yo
will have an on click event. If you select the event procedure fro
the drop down list you will open a class module for the form that ha
the button. it will look like this.

Private Sub ButtonName_Click()
End Sub

Between these two lines you need to enter

dim strWhere as string

strWhere = "Department = " & DepartmentNumber

DoCmd.OpenForm "FormName",,strWhere

Where the name of the field in the table is Department and Departmen
Number is value of department that you want to display based on thi
button. If departmentnumber is text then you will need to have singl
quotes around it
 
Back
Top