Solved

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

Posted on 2014-01-29
3
1,367 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

726 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