Passing values between forms using vba (1 Viewer)

giovi2002

Registered User.
Local time
Today, 15:03
Joined
Apr 12, 2005
Messages
83
I have one dialog form which can receive values from multiple forms.
For each form i can build a popup dialog version but that's to much time in administration later on.

The best thing is if i Can declare a variable from the source form and pass it to the target control box in the dialog form.
I tried many ways but currently it's not working.

Maybe you've got example code for me.
Thanks
 

giovi2002

Registered User.
Local time
Today, 15:03
Joined
Apr 12, 2005
Messages
83
I'm afraid openargs is only being used to find records, not to add a value in a new record
 

RuralGuy

AWF VIP
Local time
Today, 16:03
Joined
Jul 2, 2005
Messages
13,826
You can pass as many values as you like in the OpenArgs.
 

giovi2002

Registered User.
Local time
Today, 15:03
Joined
Apr 12, 2005
Messages
83
Yes, pass values but can i use these values to fill a new record??
 

RuralGuy

AWF VIP
Local time
Today, 16:03
Joined
Jul 2, 2005
Messages
13,826
Of course! If the next form is adding records and is bound to a query/table, then just put something like this in the Load event:
Code:
Private Sub Form_Load()

Dim Args As Variant

If Not IsNull(Me.OpenArgs) Then
    '-- Form is being opened from a form passing it data
    Args = Split(Me.OpenArgs, ";")  '-- We used the ";" as a delimiter
    Me.txtBox1 = Args(0) ' 1st value
    Me.txtBox2 = Args(1) ' 2nd value
    Me.txtBox3 = Args(2) ' 3rd value
    Me.txtBox4 = Args(3) ' 4th value
.
.
    Me.txtBoxN = Args(n) ' Nth value
End If

End Sub
 
Last edited:

giovi2002

Registered User.
Local time
Today, 15:03
Joined
Apr 12, 2005
Messages
83
Ok think i found a way:

Make a public function for instance:

Public Function PassValue(A)
PassValue = Forms![Vw_Sender]![Sender_Id]

End Function

This function will store the number of sender_id (a control) of the form vw_sender. It will take the number for the open record.

In your 'retrieving' (target) form you can place the function as a default value
like
=passvalue("A")

Your new record will show the value of the active form

Of course theree's a booby trap when you open your target form while the source isn't open. Or..in another case if you have multiple source forms for your target form.

The way to go is to put the function in the on load event of the form and use an if formula to decide which form is opened cq active
 

giovi2002

Registered User.
Local time
Today, 15:03
Joined
Apr 12, 2005
Messages
83
sorry rural i was posting when you were posting, will check it out!
 

giovi2002

Registered User.
Local time
Today, 15:03
Joined
Apr 12, 2005
Messages
83
Ok rural thanks it's working!!
 
Last edited:

giovi2002

Registered User.
Local time
Today, 15:03
Joined
Apr 12, 2005
Messages
83
This shows rural's way when passing data of different data types . You can use conversion functions.


Private Sub Knop12_Click()
On Error GoTo Err_Knop12_Click
Dim intFld3 As String
Dim stDocName As String
Dim stLinkCriteria As String



stDocName = "Vw_Test2"
intFld3 = CStr(Me.Sender_Id) + ";" + Me.Sender
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd, acDialog, intFld3

Exit_Knop12_Click:
Exit Sub

Err_Knop12_Click:
MsgBox Err.Description
Resume Exit_Knop12_Click

End Sub

Private Sub Form_Load()
Dim Args As Variant

If Not IsNull(Me.OpenArgs) Then
'-- Form is being opened from a form passing it data
Args = Split(Me.OpenArgs, ";") '-- We used the ";" as a delimiter
Me.Fld3 = CInt(Args(0)) ' 1st value
Me.Fld2 = CStr(Args(1)) ' 1st value
End If


End Sub
 

RuralGuy

AWF VIP
Local time
Today, 16:03
Joined
Jul 2, 2005
Messages
13,826
giovi2002,

You should really use the string concantenation character "&" not the math operator "+" when joining strings. They are often interchangable but you could also get unexpected results. I believe you understand my code sample completely. Thanks for posting back. rg
 
Last edited:

MelanieP

Registered User.
Local time
Tomorrow, 01:03
Joined
Jun 22, 2005
Messages
22
would you be able to use this when you enter a value in a text box in 1 form and passing that value to a main form. how would a person go about doing that i use access 2.0
 

RuralGuy

AWF VIP
Local time
Today, 16:03
Joined
Jul 2, 2005
Messages
13,826
I'm sorry Melanie but I too have no knowledge of Access v2.0. You could try it and see.
 

Users who are viewing this thread

Top Bottom