Solved

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

Posted on 2014-01-29
3
1,247 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
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.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

929 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

12 Experts available now in Live!

Get 1:1 Help Now