OpenForm WhereCondition based on field in current record

edh

Registered User.
Local time
Today, 00:12
Joined
Aug 29, 2012
Messages
11
Hi there , I have a form opening in datasheet view. When I double click on the ID field of a particular record I want it to open a form in form view on that record so this is what I came up with:

Code:
Private Sub BookingNo_DblClick(Cancel As Integer)
Dim strBookingNo As String
strBookingNo = Me![BookingNo]
DoCmd.OpenForm "Bookings", acNormal, , "Bookings![BookingNo]=strBookingNo", acFormReadOnly, acWindowNormal
End Sub

Now I'm only a newbie but I thought I'd done alright here, only this causes an input box with title: "Enter Parameter Values" and msgTxt: "strBookingNo"

I have used the debugger to check and variable strBookingNo is taking the value it should but the Where Condition argument doesn't seem to take it. I'm sure the problem is with my lack of understanding of how the argument is formed but I've looked around and found no help with this particular pickle.

Thanks in advance
 
Change this:
"Bookings![BookingNo]=strBookingNo"

to this:
"[BookingNo]=" & Chr(34) & strBookingNo & Chr(34)

the Chr(34)'s are double quotes and is easier for me than using triple double quotes """.

And if BookingNo is numeric instead, you would use

Dim lngBookingNo As Long

"[BookingNo]=" & lngBookingNo
 
Beautiful. It is numeric so I used your Long integer based format. Thanks very much, I had tried something similar to that but without the ampersand. I guess I am writing an SQL argument and should imagine it being printed into a query as message text would be printed into a msgBox. Out of interest did you suggest a long in place of integer purely for the extra space or is there another reason a Long is better. Either way, thanks a lot!
 

Users who are viewing this thread

Back
Top Bottom