Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a specific Record using OpenArgs

Status
Not open for further replies.

ojasg

Technical User
Mar 19, 2010
30
DE
I have two forms, both connected to the same table.
On closing FormB, I would like to pass a field value as OpenArgs to FormA, and Open FormA

On Opening FormA, I would like to go to that record in FromA which as the FieldValue = OpenArgs, and directly display this specific record only, out of the several.

I have tried several iterations and failed.

Please Help Out!

Thank You!
 
I wouldn't use the OpenArgs. I think the WHERE CONDITION is more appropriate.
Code:
Dim strWhere as String
strWhere = "[NumericFieldName]=" & Me.txtNumericField
DoCmd.OpenForm "FormB", , , strWhere
If the field is text, try:
Code:
Dim strWhere as String
strWhere = "[TextFieldName]=""" & Me.txtTextField & """ "
DoCmd.OpenForm "FormB", , , strWhere

Duane
Hook'D on Access
MS Access MVP
 
I keep getting error.
TWONumber is an AutoNumber.

I have what you suggested in addition to this -->

strWhere = TWONumber.Value

DoCmd.OpenForm "frmToolingWorkOrderDuplicate", , , strWhere

It's not working. I get this error -->

"You can't reference a property or method for a control unless the control has focus"

Please let me know how I can fix this.
Is it because of AutoNumber?
 
Why doesn't your strWhere equal something like I suggested? You have a single value while my code has a field name and "=" in quotes with a reference to a control in the current form.

Duane
Hook'D on Access
MS Access MVP
 
strWhere = "TWONumber =" & Me.TWONumber
DoCmd.OpenForm "frmToolingWorkOrderDuplicate", , , strWhere
DoCmd.Close acForm, "frmCloseToolingWorkOrder"

Yes I had tried this above code. It did not work.
However,

strWhere = "TWONumber =" & Me.TWONumber
DoCmd.Close acForm, "frmCloseToolingWorkOrder"
DoCmd.OpenForm "frmToolingWorkOrderDuplicate", , , strWhere

Works! So changing the order of opening and closing the forms made a difference! Not sure why. But your code now works flawlessely. Thanks a lot for helping out.. I am not reqired to write these databases, but they help me a lot and generous programmers like you always come to my rescue when I am stuck.
Thanks so much .. Cheers!

Also, just out of curiosity. What is difference between -->
TWONumber.Value and "TWONumber =" & Me.TWONumber

Thank You!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top