[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Access 2003; Pass information between forms

Posted on 2011-10-08
21
Medium Priority
?
273 Views
Last Modified: 2012-06-27
If I pick an order in a form, I want to open the information in a different form by passing the OrderID.

I'm sure there are multiple methods in doing this.  any suggestions?

Thanks
0
Comment
Question by:OnsiteSupport
  • 8
  • 7
  • 4
  • +1
21 Comments
 
LVL 19

Expert Comment

by:MINDSUPERB
ID: 36936431
The link below would be a good starting point:

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_26540269.html

Sincerely,
Ed
0
 
LVL 19

Expert Comment

by:MINDSUPERB
ID: 36936456
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 36936680
It pretty straight forward. Example:

1) Button on the Form to open the other form:

Private Sub btnOpenOrder_Click()
    DoCmd.OpenForm "Form1", , , , , , OpenArgs:=Me.OrderID
End Sub

2) Load event of form you are opening:

Private Sub Form_Load()
     Me.Filter = "[OrderID] = " & CLng(Me.OpenArgs)  ' assumes OrderID is Numeric
     Me.FilterOn = True
End Sub

This will open the form filtered on the OrderID from the other form.

mx
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 61

Expert Comment

by:mbizup
ID: 36936871
You can also do this from a single event procedure such as a command button on the form used to open the other form, like this:

docmd.openform "YourFormName", WhereCondition:="[OrderID] =" & me.OrderID

If OrderID is Text:

docmd.openform "YourFormName", WhereCondition:="[OrderID] =" & chr(34) &  me.OrderID & chr(34)

The difference between filtering as in MX's post and using a WhereCondition like this is that the WhereCondition effectively reduces the recordsource to just the record(s) with the specified orderID.  To get back to all records or a different set of critera, you would have to close the form and reopen it with no criteria (or different criteria).

Filtering on the other hand, keeps the recordsource the same (all the records) but just displays those with the specified criteria.  You can turn the filter off, or change the filter without closing and reopening the form.

Either method will work; it all depends on preference and/or needs.

0
 
LVL 75
ID: 36936880
Huh?  Filtering requeries the data source, filtering down to the specified records ... effectively the same as opening with a WHERE clause.

mx
0
 
LVL 75
ID: 36936939
In fact, from Help:

"The Filter property is a string expression consisting of a WHERE clause without the WHERE keyword. "

mx
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36936949
Yup you're right - I was sure I had tried mixing filtering with a Where clause with a total lack of success in the past.  

Just tried it again and both methods work exactly the same.

I almost never use filtering when opening a form myself (probably apparent from my last comment :-) ).  I generally just use the one-liner with the WhereCondition for any criteria.
0
 
LVL 75
ID: 36936972
In general, OpenArgs is potentially more versatile ... as you can pass multiple values and use Split() in the Load event.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36937062
The flexibility is definitely there and I use openargs for plenty of other things... I've just personally never needed it for filtering records (so it doesn't justify the extra code for me).

Just boils down to preferences and needs.
0
 

Author Comment

by:OnsiteSupport
ID: 36937072
Works Great!!!!
Is there a way to avoid a NULL error if I open the form without passing OpenArgs?  I also would like to open the 2nd form directly without being called from the 1st.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36937086
You can add a check to see if openargs are present.  Mx can show you how to do that since it complements his method.

GIve this a try too - without the openargs:

docmd.openform "YourFormName", WhereCondition:="[OrderID] =" & me.OrderID

0
 
LVL 75
ID: 36937088
Who are you asking the question to?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36937090
Just to be clear, that should be tried without the load event code.
0
 
LVL 75
ID: 36937093
What Null condition ?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36937242
mx,

With the code in the load event, the form won't open unless it is opened with the OpenForm statement with OpenArg criteria (invalid use of null when OpenArgs aren't specified).   For it to work in other contexts, the Load Event needs a null check.
0
 
LVL 75
ID: 36937475
Right.  However, no other context was mentioned per se.  And your method would not use that code in the Load event.

Anyway ..

To cover no OpenArgs ....

Private Sub Form_Load()
    If Nz(Me.OpenArgs, "")>"" Then
          Me.Filter = "[OrderID] = " & CLng(Me.OpenArgs)  ' assumes OrderID is Numeric
          Me.FilterOn = True
    End If
End Sub
0
 

Author Comment

by:OnsiteSupport
ID: 36938402
 In the load event:
Will this work?
 if isnull(Me.OpenArgs) then Me.Filter = "[OrderID] = " & CLng(Me.OpenArgs)
     Me.FilterOn = True
Else
 Just load the form and pray the end user doesn't want any more modifications to this application.
End if
0
 

Author Comment

by:OnsiteSupport
ID: 36938406
 In the load event:
Will this work?
 if isnull(Me.OpenArgs) then Me.Filter = "[OrderID] = " & CLng(Me.OpenArgs)
     Me.FilterOn = True
Else
 Just load the form and pray the end user doesn't want any more modifications to this application.
End if
0
 

Author Closing Comment

by:OnsiteSupport
ID: 36938418
Thanks!!
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36938419
Offhand, That should do the trick.

The best test of course is always your own...

Does it run without error when you simply double click the form's name in the database window rather than calling it from code that passes openargs?
0
 
LVL 75
ID: 36939106
" Just load the form and pray the end user doesn't want any more modifications to this application."

ha ha ... that never happens!

mx
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question