Passing values to another form WITHOUT opening it?

B

bronen

Is it possible to pass multiple values to another form without opening the
2nd form?
I have the OpenArgs procedure but it uses docmd.openform. See code below.
What can I use to avoid the openform procedure?

Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click

Dim stDocName As String, strArgs
Dim stLinkCriteria As String
strArgs = cboProjectNumber & "," & cboProjectName
stDocName = "Child"

If Not IsNull(cboProjectNumber) And Not IsNull(cboProjectName) Then
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd, , strArgs
Else
MsgBox "You must fill in all values"
End If
Exit_cmdAdd_Click:
Exit Sub

Err_cmdAdd_Click:
MsgBox Err.Description
Resume Exit_cmdAdd_Click

End Sub

------

Option Compare Database
Option Explicit

Dim arg1 As String, arg2 As String


Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click


DoCmd.Close

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click

End Sub

Private Sub Form_Load()
If arg1 <> "" And arg2 <> "" Then
Me!ProjectNumber = arg1
Me!ProjectName = arg2
'End If
'If arg2 <> "" Then
'Not IsNull(arg2) Then

End If
End Sub

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

Dim temp As String
temp = Nz(Me.OpenArgs)
If temp <> "" Then
arg1 = Left(temp, InStr(temp, ",") - 1)
temp = Mid(temp, InStr(temp, ",") + 1)
arg2 = Left(temp, InStr(temp, ",") - 1)
temp = Mid(temp, InStr(temp, ",") + 1)


End If
Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Error$
Resume Exit_Form_Open

End Sub


ANY help would be greatly appreciated!

Ben
 
M

Michel Walsh

Nope, technically, a FORM is like a blue print of something. When you open
the form, you effectively create it (in fact you create ONE object from the
blue print specifications, since, indeed, you can open a given form multiple
time, through VBA). So, if you need the other form to be active because you
will refer to one of its control, as example, then the form-OBJECT must
exist in memory. If you don't need to open the second form, then simply
comment out the DoCmd.OpenForm line.


Hoping it may help,
Vanderghast, Access MVP
 
A

Albert D. Kallal

You have to expand a bit on what you trying to accomplish here.

How can you pass something to a form that is not yet opened?

In many cases, you don't have to use openargs to pass things, or have the
form pickup values.

Often, (if not most of the time), you form code will need to pick up
some information about the calling form, then I just pickup the
name of the calling form in the on-load, or on-open
(screen.activeform is the CALLING form name UNTIL on-load is done!!!).

So, my code most of the time
starts out, and grabs the current screen name. I use the following in
the forms on-load event

Set frmPrevious = Screen.ActiveForm

Now, in this form, I can pull out any values I want:

msgbox "the project number is " & frmPrevious.cboProjectNumber

So, often, you can just pass the form name also.

eg:

set frmPrevious = forms(me.OpenArgs)

And again you a now reference any values in the calling form such as

frmPrevious!cboProjectName

I not sure where you going with this, but the form does have to be opened.
Perhaps you mean that you have a form already open, but would like to send
it some values?

That is easy.

Just declare your arg1, and arg1 as public variables in the module level in
the form. Then go

forms!frmCoolForm.form.arg1 = "hello"

You can reference any variable that way. And, then, to execute a function in
that "other" form, you can go

frms!formCoolForm.form.MyPublicFunctionNameToExecute

If you make variables and functions public, then other code outside of that
form can set those vairlaes..and then call code in that form....
 
B

bronen

Albert,
Here is what I want to do. I have a form A that has two unbound text boxes.
I have a Form B that has two fields Project Number and Project Name. I want
to have a command button that when i click it, the data in Form B pulls the
data from Form A and stores it in the table. That's all I want to do.

How do I do this?

Ben
 
D

Damon Heron

You don't need form B. Just put the code in the command button to write the
text data to the table.

HTH
Damon
 
A

Albert D. Kallal

bronen said:
Albert,
Here is what I want to do. I have a form A that has two unbound text
boxes.
I have a Form B that has two fields Project Number and Project Name. I
want
to have a command button that when i click it, the data in Form B pulls
the
data from Form A and stores it in the table. That's all I want to do.


This button is on form a ??

just go:

me.ProjectNumber = forms!formA!cboProjectNumber
me.ProjectName = forms1formA!cboProjectName

It really depends on how you are opening form "a". This is form already
opened, or do you plan to have a button on formB that opens the
formA...allows the users to select the combo values, and then return the
values to formB. The trick is not grabbing the values from fromA, but the
trick is in what context you need to actually open formA and grab the
values.

I explain in detail here how to "call" a form...ask for some values...and
then return those values. So, you could use the following to have a button
on formB that would open the form with the combo boxes...and then return the
values selected in the combo boxes.

http://www.members.shaw.ca/AlbertKallal/Dialog/Index.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Criteria when opening form 1
I am not "getting" it.....DoCmd. OpenForm 4
Error 2237 8
If Statements 4
Multiple Criteria in Code 13
Choose report does not work in 2007 0
Using a wildcard to open a form 2
OutputTo 3

Top