automatically fill field with form information

G

Guest

I have a form for COMPANY, and using some of the information in this record,
want to create a separate form for invoice, having the field "CompanyName"
fill in automatically. then from there, I am creating another form to enter
Serial Numbers, filling in three fields automatically, so I can just type in
the S/N, then hit the "New" button, enter another S/N, etc. How do I get the
fields from the first form, to fill in on the second form, and cascade that
information. The goal is to have a list of S/N's with invoice date for
warranty purposes.

I have hardly done anything with Access since taking a course 6 years ago,
so this is a challenge.
Thank you.
 
J

JP

Six years is a long time <g>

You say that you have a form for COMPANY and that you want to use "... some
of the information in this record ...". Does that mean that the form is
bound to some sort of table that stores the company information? If so,
then the easiest (or at least one of the easiest ways to do it) is the
following:

On the S/N form (assume it's called frmSN_form), have a field to hold the
company name (called it txbCompany for example). In the "OnCurrent" event
of the S/N form, specify an event procedure. Your code for the event
procedure will be a dlookup to the company name in the Company table that
puts the result in the txbCompany field.

Another way to do it is to pass the company name to the S/N form. This
approach works best if you are opening the S/N form from the Company form
(e.g., you have a command button on the Company form that opens the S/N
form). There are two ways to do this:

1. Create a property of the S/N form to hold the Company name and pass the
name to the property when you open the S/N form (you do this in code after
you've opened the S/N form but before you close the Company form)

2. Create a text box on the S/N form to hold the Company name. When you
open the S/N form, but before you close the Company form, put in a line of
code like this

forms!frmSN_form!txbCompany = me.txbCompany

(this assumes that the field with the company name is called txbCompany on
both the Company form and the S/N form)

Finally, if the Company form gets closed before the S/N form gets opened,
you can try this approach (it's not considered the most "elegant", but it
does work)

Go to modules and create a module. Define a GLOBAL variable called
gsCompany_Name. Before you close the Company form, have a line of code in
the form module that says something like gsCompany_Name = me.txbCompany.
Then put an "OnCurrent" event in the S/N form that says me.txbCompany =
gsCompany_Name.

This last approach stores the Company name in the global variable, and then
retrieves it from the global variable for each S/N record. Just be
careful -- it will retrieve it for EACH S/N record. If you have multiple
companies in this system, you could wind up screwing things up.
 
M

Mike Painter

Tina said:
I have a form for COMPANY, and using some of the information in this
record, want to create a separate form for invoice, having the field
"CompanyName" fill in automatically. then from there, I am creating
another form to enter Serial Numbers, filling in three fields
automatically, so I can just type in the S/N, then hit the "New"
button, enter another S/N, etc. How do I get the fields from the
first form, to fill in on the second form, and cascade that
information. The goal is to have a list of S/N's with invoice date
for warranty purposes.

I have hardly done anything with Access since taking a course 6 years
ago, so this is a challenge.
Thank you.
The Northwind database has samples of what you want to do.

You should have a table that contains the invoice header information, who
it's sold to etc.
Another table holds detail information.
You would built a form for the header and a form for the detail and add the
latter to the former making a subform.

The invoice header table will contain a field for the company ID plus
whatever is needed.
Your header form would be based on a query joining the header table and the
company.
Filling in the companyID field for on the invoice header will automatically
fill in the rest of the company data.

Again the Northwind database has examples of this. For what you are
describing, if done properly with related tables
NO BUTTONS ARE NEEDED.
NO CODE IS NEEDED THAT ACCESS WILL NOT WRITE FOR YOU.

Be lazy and learn to use the power of a relational database. Less code is
better.
 

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

Similar Threads


Top