Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Value from one form to another

Status
Not open for further replies.

tizwaz

Technical User
Joined
Aug 8, 2002
Messages
437
Location
GB
I am trying to open a form and pass the LastName from the open form to the new form. My code is as follows. When I run it I get Name# in the Last Name box.

Private Sub Command10_Click()
Dim strLastName As String
strLastName = Me.txtLastName
DoCmd.Close acForm, "frmStaff"
DoCmd.OpenForm "frmStaffNew"
DoCmd.GoToRecord , , acNewRec
Forms!frmStaffNew!txtLastName.DefaultValue = strLastName

Anyone know what I'm doing wrong?
 
Your problem is the scope of strLastName. When you close frmStaff, strLastName no longer exists. You should either make strLastName a global variable, or not close frmStaff until you have assigned the variable to the frmStaffNew textbox.

Tranman

"Adam was not alone in the Garden of Eden, however,...much is due to Eve, the first woman, and Satan, the first consultant." Mark Twain
 
Hi

See .OpenArgs in Help, I think you will find it is an easier way to achieve this




Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top