query open a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

is there any way to have a parameter query open a form? I want users to be
able to type in an order number and bring up just that entry in form view.
Thanks
 
Harvey,

Yes, there is, but this is quite unusual and, frankly, rather abnormal.
Why would you have the user run a query to open a form? Users should
never even see queries! It would be much better to do it by means of a
command button on a switchboard or other form; picture this: there is a
control (textbox or listbox or combo) where the user types in / selects
an order number, and a command button right next to it which opens the
form right to the desired record (or filtered on the order ID, in the
case of line items). How about that?

HTH,
Nikos
 
On your switchboard, or other form, add a textbox called txtOrderID;
Next to it, add command button to open the orders form; follow the
wizard steps to do it for you. Then display the properties window for
the command button, select tab Event, put the cursor in the Click event
(where it reads [Event Procedure]) and click on the little button with
the ellipsis symbol on the right. You will be taken to the VBA editor,
and see the code already there, looking something like:

Private Sub Command3_Click()
On Error GoTo Err_Command3_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "CalForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command3_Click:
Exit Sub

Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click

End Sub

All you need to do is add this line of code:

stLinkCriteria = "[OrderID] = " & Me.txtOrderID

right before the DoCmd.OpenForm line. I have assumed the name of the
order number field in the orders table to be OrderID, change to the
actual name if different.

HTH,
Nikos
 
Back
Top