FilipeG
FilipeG

Reputation: 167

access passing values between non related forms

I have a main form, 1, a subform inside it, 2, and a popup form, 3.

form 2 and form 3 are datasheets. A button in form 1 opens popup form 3.

Right now, in form 2, I capture the currently selected record and setup a query with the following code:

The query is a var named strSQL.

Is it possible to set strSQL as a property of form 2 so I could set form 3 record source as Forms!1!2.forms!strSql ? If not, what are my options of moving data from form 2 to form 3, they're not related so I can't use OpenArgs.

Upvotes: 1

Views: 1291

Answers (1)

Johnny Bones
Johnny Bones

Reputation: 8402

You CAN use OpenArgs for something like this. You can pass a SQL string in OpenArgs if you wanted. In fact, you can pass MULTIPLE SQL strings in OpenArgs, as long as you parse them out correctly. I have an app where I pass 3 variables to another form using OpenArgs, and I pipe-delimit them (that is, I use the pipe key "|" to separate each variable, then parse them out when they get to the other form). You can definitely use this methodology to accomplish what you're trying to do.

As an example, I'm using this code to pass a form, subform and field name to a new form:

DoCmd.OpenForm stDocName, , , , , , stForm & "|" & stField & "|" & stSubForm

When I open that form, I'm parsing those values out using this code:

strForm = Left(Me.OpenArgs, InStr(Me.OpenArgs, "|") - 1)
Brk1 = Mid(Me.OpenArgs, InStr(Me.OpenArgs, "|") + 1)
strField = Left(Brk1, InStr(Brk1, "|") - 1)
strSubForm = Mid(Brk1, InStr(Brk1, "|") + 1)

Upvotes: 1

Related Questions