Passing Parameters between Forms

A

AltT

Hello!

I am a fairly new Access 2003 user, and I wanted to see if I could get some
help with the forms I am developing.

I'm setting up a dB to schedule our rental equipment. This involves
customer information, a list of products, a list of kits that contain
products, and start/end dates.

My trouble is finding a way to pass information from one form to another. I
have form setup to search the products and check availability dates, but I
want to add a button "Reserve Product" and have that action transfer the
order_id and product_id to a second form so that I can combine it with the
customer's information (based on customer_id) and reservation dates.

I want to keep it two different forms, because the first is setup to view
current reservations and check availability. Make sense?

I thought this would be fairly easy, but I guess my problem is that I'm too
new to Access to figure it out! Any help would be appreciated.
 
S

Sprinks

See VBA Help on the OpenForm method. You can use the optional OpenArgs
parameter to achieve what you want. It is just a string parameter; it can be
very versatile. For example,

' Pass value to use as a filter
DoCmd.OpenForm "YourForm", , , , , , "[ProductID]=" & Me![txtProductID]

' In 2nd form's OnLoad event:
If Not IsNull(Me.OpenArgs) Then
Me.Filter = Me.OpenArgs
Me.FilterOn = True
End If

Although OpenArgs is a single string value, you can send several delimited
parameters and use the Split function at the other end to parse them as
required:

' Separate elements with semi-colon
DoCmd.OpenForm "YourForm", , , , , , "[ProductID]=" & Me![txtProductID] & _
";[CustomerID] = " & Me![txtCustomerID]"

Dim astrMyArray()
Dim i as Integer
If Not IsNull(Me.Openargs) Then

' Parse components to array
astrMyArray = Split(Me.Openargs,";")

' Do something with the elements
For i = 0 to UBound(astrMyArray)
Msgbox "Element " & i & " is " & astrMyArray(i)
Next i

End If

Hope that helps.
Sprinks
 

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