OpenForm command

fat controller

Slightly round the bend..
Local time
Today, 08:14
Joined
Apr 14, 2011
Messages
758
I am trying to make use of the OpenForm command to open a form to a record where a textbox matches the value of a text box on another form.

On Form1, I have a textbox called txtRtnRef, and it contains a reference number in a similar format to SWR-9

On Form2, I have a textbox called txtReOrderRef (control source ReOrderRef) which also contains a reference number in the same format (SWR-9)

I am trying to have a button next to the text box on Form1 that has an OnClick Event that opens Form2 to the record containing the same text reference number.

I have tried, to no avail, a number of variations of the OpenForm command, the most recent being

Code:
DoCmd.OpenForm "Form2", , , "ReOrderRef = '" & Me.txtRtnRef & "'"

The form opens, but to a blank record?

Where am I going wrong?
 
Try...
Code:
DoCmd.OpenForm "Form2", , , "ReOrderRef = '" & Me![txtRtnRef] & "'"

Is there anything in the On_Open event of the second Form?
 
Try...
Code:
DoCmd.OpenForm "Form2", , , "ReOrderRef = '" & Me![txtRtnRef] & "'"
Is there anything in the On_Open event of the second Form?

Doesn't want to know that either. No On_Open event as yet (although I was thinking I would like to go to a new record when opened on its own/directly without using Form1 first -- however, I am still not certain that I will do this)
 
Have you set the "Data Entry" to "No" in Form2?

Yes - just changed it to "Yes" to see what that would do and it will only go to a new record (which is the correct behaviour if my understanding is correct?)
 
Sorted it! Probably zero finesse in my approach, but it works.
Code:
Dim varInput

varInput = [Forms]![Form1]![txtRtnRef]

DoCmd.OpenForm "Form2", acNormal
DoCmd,FindRecord varInput, acEntire, , acSearchAll, False, acCurrent

And bingo - Bob's yer uncle as they say.

I will of course add to that to fit in with the process that I am wanting, but that should be easy enough........

Famous last words (so I will probably be back!) Thanks all :)
 
As long as you got something that works, that's all that counts, glad you sorted it out!
 

Users who are viewing this thread

Back
Top Bottom