Field Populating

  • Thread starter P-chu via AccessMonster.com
  • Start date
P

P-chu via AccessMonster.com

I would like some suggestions on the best way to make this work. Two forms
based on one table. Main page has shorcut button to second page. Main page
form contains Customer First Name, Last Name and address. Second form
contains First Name, Last Name and history of purchases. How can I get the
second form page to automatically show the first and last name from the main
page without doing a search?

Thanks much.
 
R

rm

Look at the arguments of DoCmd for opening a form.

You can filter the second form - use a WHERE clause or use openargs.
 
R

rm

Example -

DoCmd.OpenForm "SecondForm", , , "[LastName] = " &
Forms![mainform]![lastname]

There are multiple ways to accomplish the goal.
 
P

P-chu via AccessMonster.com

This is what I came up with, but it is asking for a parameter value based on
the last name:
Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmSecondPage", , , "[Last Name]=" & Forms![frmMain Menu]!
[Last Name]
DoCmd.OpenForm "frmSecondPage", , , "[First Name]=" & Forms![frmMain Menu]!
[First Name]
End Sub

What am I missing please?
Example -

DoCmd.OpenForm "SecondForm", , , "[LastName] = " &
Forms![mainform]![lastname]

There are multiple ways to accomplish the goal.
Look at the arguments of DoCmd for opening a form.
[quoted text clipped - 13 lines]
- Show quoted text -
 
J

John W. Vinson/MVP

I would like some suggestions on the best way to make this work. Two forms
based on one table. Main page has shorcut button to second page. Main page
form contains Customer First Name, Last Name and address. Second form
contains First Name, Last Name and history of purchases. How can I get the
second form page to automatically show the first and last name from the main
page without doing a search?

Thanks much.

You can certainly open a second form, but the simplest approach may be
to make the second form a Subform of the first.

However, if you have ONE table containing customer identity and *also*
purchase history, your table design is incorrect. You're using a
relational database - use it relationally! There should be two tables,
one for customers (with one record per customer, and fields for a
unique CustomerID and their name and contact info); the second for
purchases, with a foreign key to the customerID and NO other customer
identity information.
 
P

P-chu via AccessMonster.com

Thank you for your assistance.
I would like some suggestions on the best way to make this work. Two forms
based on one table. Main page has shorcut button to second page. Main page
[quoted text clipped - 4 lines]
Thanks much.

You can certainly open a second form, but the simplest approach may be
to make the second form a Subform of the first.

However, if you have ONE table containing customer identity and *also*
purchase history, your table design is incorrect. You're using a
relational database - use it relationally! There should be two tables,
one for customers (with one record per customer, and fields for a
unique CustomerID and their name and contact info); the second for
purchases, with a foreign key to the customerID and NO other customer
identity information.
 
J

John W. Vinson/MVP

This is what I came up with, but it is asking for a parameter value based on
the last name:
Private Sub Form_Open(Cancel As Integer)
DoCmd.OpenForm "frmSecondPage", , , "[Last Name]=" & Forms![frmMain Menu]!
[Last Name]
DoCmd.OpenForm "frmSecondPage", , , "[First Name]=" & Forms![frmMain Menu]!
[First Name]
End Sub

What am I missing please?

Quotemarks. String values as criteria need to be delimited by either '
or " marks; since names might contain ' - O'Henry for example - use a
doublequote. To include a doublequote in a string use two consecutive
doublequotes.

Your button code will open the second form TWICE - once for all people
named Jones, regardless of their first name; and again for all people
named David, regardless of their last name. To open the form for just
David Jones combine the criteria into one using the AND operator. This
will give you David Jones - or, if as is quite possible, you have
three different customers all named David Jones - all three of them.

DoCmd.OpenForm "frmSecondPage", , , _
"[Last Name]=""" & Forms![frmMain Menu]![Last Name] _
& """ AND [First Name]=""" & Forms![frmMain Menu]![First Name] & """"
 
R

rm

I am not at all in the same league with the Mr. Vinson...

Many times is use Chr(34) for """. Makes things a bit more readable.
So "[FirstName] = " & """ & Forms![... becomes

"[FirstName]= " & chr(34) & Forms![...

I could imagine getting feedback that this makes the cpu work a bit
harder - I have never researched that.
 
P

P-chu via AccessMonster.com

Thank you for all your help to both of you. Got it working just fine.
I am not at all in the same league with the Mr. Vinson...

Many times is use Chr(34) for """. Makes things a bit more readable.
So "[FirstName] = " & """ & Forms![... becomes

"[FirstName]= " & chr(34) & Forms![...

I could imagine getting feedback that this makes the cpu work a bit
harder - I have never researched that.
I would like some suggestions on the best way to make this work.  Two forms
based on one table.  Main page has shorcut button to second page.  Main page
[quoted text clipped - 7 lines]
 

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

Top