Google Answers Logo
View Question
 
Q: Transferring data between forms in access ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Transferring data between forms in access
Category: Computers > Programming
Asked by: mattie54-ga
List Price: $2.50
Posted: 31 Mar 2003 10:28 PST
Expires: 30 Apr 2003 11:28 PDT
Question ID: 183712
I have a form named Customer in which there a field called CustomerID.
When the user clicks a button to open the next form "booking" I want
the value of CustomerID from the first form to appear in a text box in
the second form.

I don't know much VBA so need exact code or good instructions!

Thanks

Request for Question Clarification by hammer-ga on 31 Mar 2003 14:27 PST
What version of Access?

- Hammer

Clarification of Question by mattie54-ga on 01 Apr 2003 00:43 PST
It's access XP and I am working in access 2002 file format.

Thanks, matt
Answer  
Subject: Re: Transferring data between forms in access
Answered By: hammer-ga on 01 Apr 2003 05:12 PST
Rated:5 out of 5 stars
 
There are several ways to do this. I'm giving you the one that is most
generic.

The following code is based on having the following elements:

Form - frmCustomer
Text Box - txtCustomerID
CommandButton - cmdBookings

Form - frmBookings
Text Box - txtCustomerID

Paste the following routine into the module for frmCustomer. It will
run when the button is clicked.

' Code Begin
Private Sub cmdBookings_Click()
On Error GoTo Err_cmdBookings_Click

    ' This is the important line
    DoCmd.openform "frmBookings", , , , acFormAdd, ,
CStr(txtCustomerID)

Exit_cmdBookings_Click:
    Exit Sub

Err_cmdBookings_Click:
    MsgBox Err.Description
    Resume Exit_cmdBookings_Click
    
End Sub
' Code End

Most of the above routine is error handling. The important line is
marked. This routine opens the form called frmBookings to a new
record, passing your CustomerID to frmBookings as an argument.
DoCmd.OpenForm has lots of options you can use to get what you want.
See Access' help for this command to tweak it to fit your needs.

The other half of this is that frmBookings needs to use the
CustomerID. Paste the following routine into the module for
frmBookings.

' Code Begin
Private Sub Form_Load()

    txtCustomerID = Me.OpenArgs

End Sub
' Code End

This routine reads the ID passed by OpenForm and puts it into the text
box. If you want to add more than one record, you may want to move
this to the FormCurrent event instead of FormLoad, which will only set
the first record.

Additional Resources:
See Access Help for DCmd.OpenForm and OpenArgs.

Good luck with your Access project!

- Hammer

Clarification of Answer by hammer-ga on 01 Apr 2003 05:12 PST
Note: The Answer Box may cause lines to wrap. No line of code in the
above routines should wrap.

- Hammer

Request for Answer Clarification by mattie54-ga on 01 Apr 2003 12:17 PST
Hi, thanks for your answer. I tried this but no data appears in the
field on the second form. Do I need to edit the data source for this
field?

Thanks, matt

Clarification of Answer by hammer-ga on 01 Apr 2003 12:38 PST
At this point, there could be any number of things wrong. You may have
the code in the wrong place. You may have things named differently,
etc... Could you post your database online somewhere that I can
download it and look for the problem?

Make especially sure that you have updated the code to match whatever
your forms and controls are actually named.

Let me know if you can post your database.

- Hammer

Request for Answer Clarification by mattie54-ga on 03 Apr 2003 04:01 PST
Hi, its working!! I had a final mess around with it as I was uploading
it and it started working! Thanks very much for your help. I may have
some other questions for you very soon! Please look out for them!
thanks for your help, matt

Clarification of Answer by hammer-ga on 03 Apr 2003 04:43 PST
I'm glad you got it working. I'll keep an eye out for your other questions.

- Hammer

Request for Answer Clarification by mattie54-ga on 03 Apr 2003 07:58 PST
New question! "Access database - help needed"

your help would be appreciated! and i will tip if you get it working!
just dont want to put too much money on it in case I get an answer
which I can't understand!!

cheers, matt (project is almost finished :-))

Clarification of Answer by hammer-ga on 03 Apr 2003 08:34 PST
I'll go look for it.

- Hammer
mattie54-ga rated this answer:5 out of 5 stars
thanks very much. very good answer and want your help with more :-)

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy