Solved

Passing Information to New (Add, not Edit) Access Forms

Posted on 2014-01-29
3
1,217 Views
Last Modified: 2014-01-30
I'm working on building a database through Access 2010 which will keep track of jobs and "records" (here, essentially components of a job, like a bid).  These two aspects of a job are in their own, separate tables, with the Primary Key of the JobT Table being a foreign key in RecordT.  I currently have a Navigation Form set up with a subform that displays a list of current records/bids.  At the end of this subform, I have a button labelled "Job Info" that leads to a different form that displays all the details of this job, and includes a subform of the bids that make up a job.  There is another button, right next to this one, that opens a form with details about the bid (call it Record Info).  Both of these forms allow reading as well as writing information, and this is by design.

My question is:  is there any way to open the "Record Info" and pass specific values to certain fields on the new form?  In this case, I'd like to pass only the JobID value into the new form only when the button on the Job Info form is pressed (along with other job-specific things that can be brought over if I have this JobID field (which is a Primary Key)).

Essentially, I would like to re-use the Record Info form thusly:
1: pressing the "record info" button at the end of a line in a subform should open that record's information.
2: pressing the "log new record" button (on the Job Info form) should open this form in data entry mode, automatically passing and pulling certain information based on information in the form that called this one.

The end result of this form's submittal should be that the new record is added to the RecordT table, and it should be automatically assigned to the appropriate job.  This can be accomplished using a dialog box or text/combobox, whichever seems simpler.

Thanks in advance!
0
Comment
Question by:calwood28
3 Comments
 
LVL 20

Accepted Solution

by:
GrahamMandeno earned 250 total points
ID: 39819750
Hello calwood28

To achieve #1, pass the RecordID from the current record as a WhereCondition when you open the form:
DoCmd.OpenForm "Record Info", _
        WhereCondition:="RecordID=" & Me.RecordID, _
        WindowMode:=acDialog

Open in new window


For #2, open the form in DataEntry mode and pass the JobID through the form's OpenArgs:
DoCmd.OpenForm "Record Info", _
        DataMode:=acFormAdd, _
        WindowMode:=acDialog, _
        OpenArgs:=Me.JobID
' then requery the subform
Me.[Name of subform control].Form.Requery

Open in new window


In the form's Load event procedure, check for DataEntry mode and set the DefaultValue of the JobID textbox to the passed value:
If Me.DataEntry Then Me.JobID.DefaultValue = Me.OpenArgs

Open in new window


The reason for using .DefaultValue instead of just setting the .Value is that if the user changes her mind and closes the form immediately, no new record will have been created to undo.

Best wishes,
Graham Mandeno [Access MVP 1996-2014]
0
 
LVL 30

Expert Comment

by:hnasr
ID: 39819812
One way:
Have unbound controls on the calling form.
Populate the controls with relevant values when clicking respective button.
In the open form in new record, use the previous controls.
0
 

Author Closing Comment

by:calwood28
ID: 39821960
That worked wonderfully, thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now