Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

2nd form won't get record number from 1st form

I have a form we'll named frmAddMemberHospitalVisit.  On this form is a command button that opens form 2.  On form 2 I have a field that I want to populate with the data from a field on form 1.  

In the default value setting for the field on form 2 I have:

=[Forms]![frmAddMemberHospitalVisit]![txtHospitalVisitID]

But it is not populating with anything.  I've done this countless times before but can't figure out why it isn't working this time.
0
SteveL13
Asked:
SteveL13
  • 3
  • 2
1 Solution
 
SteveL13Author Commented:
I also tried this in the onopen event of the 2nd form...

Me.txtHospitalVisitID = Forms!frmAddMemberHospitalVisit.txtHospitalVisitID

But I get an error...  "You can't assign a value..."
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Is the recordset for Form2 updateable?

If Form2.txtHospitalVisitID bound to a field in the form's underlying recordset?
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Also, do this in the Open or Load event of Form2:

Msgbox Forms!frmAddMemberHospitalVisit.txtHospitalVisitID

Does a message pop up with the correct value?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
SteveL13Author Commented:
I moved the code to the onload event and it worked.
0
 
PatHartmanCommented:
A better event to use is the BeforeInsert event.  That event runs as soon as you dirty the first field on the form and it only runs once for each new record.  Using this event prevents you from dirtying the form.  When the program dirties a form, the user can get confused because he knows he didn't touch anything and yet, he will get bombarded with error messages if he tries to close the form without entering anything else.

Knowing when events fire will go a long way toward gaining control over how bound forms work.  The code wouldn't work in the Open event because the form's RecordSource had not yet been loaded.  The code sort of works in the Load event where you have it now but it will only work ONCE.  If the user adds a second record, the code will not fire.  By using the correct event - BeforeInsert, it doesn't matter how many records the user enters.  Each one will have the foreign key populated and you won't be dirtying the form and causing user confusion.
0
 
SteveL13Author Commented:
Great suggestion.  Thank you.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now