Open args code (pass values) new to coding

R

Rpettis31

I want to pass some values from one form to another. I have a form
custsvcissue that is filled out by customer service with fields item and
problem etc. The quality department review this form and if necessary
selects a button which opens a new form (frmCar) for follow up activities.

I would like to pass the problem and items fields to the new form in the
same named fields on the new form.

Thanks
 
G

Graham Mandeno

When I need to pass multiple data to a form or report through OpenArgs, I
create a single string with the items separated by Null characters
(vbNullChar). Then, the Load event of the form can split up the string into
the individual elements.

You may find these two functions useful:

Public Function MakeOpenArgs(ParamArray Args()) As String
Dim i As Integer, s As String
For i = LBound(Args) To UBound(Args)
s = s & Args(i) & vbNullChar
Next
MakeOpenArgs = Left(s, Len(s) - 1)
End Function

Public Function SplitOpenArgs(Args As Variant) As Variant
SplitOpenArgs = Split(Args & "", vbNullChar)
End Function

You can then call OpenForm like this:
DoCmd.OpenForm "frmCar", OpenArgs:=MakeOpenArgs(Me.Item, Me.Problem)

Then, in your Load event for frmCar:
Dim Args as Variant
Args = SplitOpenArgs(Me.OpenArgs)
txtItem = Args(0)
txtProblem = Args(1)
 
D

Dale Fye

Another way to do this is to hide the original form when you open frmCar,
rather than closing it.

Then, you can just refer to the controls on the other form in Open event of
frmCar, something like:

Private Sub Form_Open

if currentproject.allforms("frm_FirstForm").isloaded Then
me.txt_FirstField = Forms("frm_FirstForm").txt_FirstField
me.txt_SecondField = Forms("frm_FirstForm").txt_SecondField
endif

End sub
 
R

Rpettis31

I like this idea however the second frmCar will need to be opened on its own
for review as different departments handle different forms. However certain
key pieces of information need to be passed along on the different forms.

Thanks
RObert
 

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

Top