Form with VB code

Shoo

Registered User.
Local time
Today, 22:57
Joined
Apr 26, 2005
Messages
22
hey can anyone please explain how to adjust the below code to open the specific order ID that has been double clicked? At the moment no matter which order is double clicked the same order is opened.

Private Sub OrderID_DblClick(Cancel As Integer)
On Error GoTo Err_OrderID_DblClick

Dim stDocName As String
stDocName = "Orders"
DoCmd.OpenForm stDocName



Exit_OrderID_DblClick:
Exit Sub

Err_OrderID_DblClick:
MsgBox Err.Description
Resume Exit_OrderID_DblClick


End Sub

Thanks in advance.
 
Look up 'filter' in Access vba Help...
 
Thanks I will look it up.

What's strange is that the exact same code (with name adjustments) works for the products list.
 
Last edited:
The only part of the code that you posted that does anything is the 'DoCmd.OpenForm' stuff. Access helps does that pretty good too.
 
I am completely stuck. I need the code to specify that the order that has been double clicked should open. This principle works fine for my products and customer datasheets without any need for additional filters but not so for the order double click code it seems.
 
The OpenForm method has additional arguments that let you specify a where clause (without the "where") for the form you are opening. OpenForm is what you need to search help for. The following shows a "where" clause in which the OrderID is numeric. If OrderID is text, it needs to be enclosed in quotes.

DoCmd.OpenForm stDocName, , , "OrderID = " & Me.OrderID

Or

DoCmd.OpenForm stDocName, , , "OrderID = '" & Me.OrderID & "'"
 
Ah Hah!

DoCmd.OpenForm stDocName, , , "OrderID = '" & Me.OrderID & "'"

Ah hah! My problem was similar and this is the bit of code I was after. Why is the syntax for text different than for everything else?
 
As a general rule, anytime you reference a pc of text, you need the quotes. I suspect the main reason is because if you didn't, the program would not know where the string started and ended;

myString = "hello, its a small world!"

vs

myString = hello, its a small world!

Hope this make sense :)
 

Users who are viewing this thread

Back
Top Bottom