adding a record from a form to another form

G

Guest

Hi: I have one form called Participants and have a button that when clicked
takes me to a registration form. I would like it to carry over some
information from the participants form, open a new record in the registration
form. This is the code I have for my register button:

DoCmd.Close (which closes the participant form)
DoCmd.OpenForm "frmRegistrations", acNormal
DoCmd.GoToRecord , , acNewRec

When I click the register button it takes me to the registration form but it
does not seem to be adding a new record.

Can anyone please tell me what I am missing???? Thanks muchly!!!
 
N

Nikos Yannacopoulos

I'm not sure why the .GoToRecord , , acNewRec doesn't work; it's
probably a redundant step anyway, though, since you can open the form
for adding new data only:

DoCmd.OpenForm "frmRegistrations", acNormal,,,acFormAdd

which will automatically take you to anew record anyway. Now, on
transferring some data cross from the previous for, the trick is to open
the second form first, copy the data, then close the original form...
something like:

DoCmd.OpenForm "frmRegistrations", acNormal,,,acFormAdd
Forms!frmRegistrations.SomeControl = Me.ControlX 'etc
DoCmd.Close Me.Name

HTH,
Nikos
 
G

Guest

Hi: thanks for the reply. I will try those new codes that you indicated.

Can you explain the code about transferring the data though: Not sure what
you mean by ".somecontrol = me.controlX 'etc"

I want to copy of the first name and last name over to the registration
form, what I had in a text box on the registration form was
=forms!frmparticipants!lname & " " & forms!frmparticipantsfname. And this
does work but it doesnt go to a new record it just replaces the name that is
already there. So I should write this out in code as well? Thanks again!
 
N

Nikos Yannacopoulos

Forms!frmRegistrations.SomeControl = Me.ControlX

is just an example of how to "copy" the value of control ControlX in the
form in whose module the code is, to control SomeControl in
frmRegistrations. The names of the controls are just hypothetical
placeholders in the example, they do not mean anything. The Me. keyword,
when used in a form's (or eports) own module, is simply a shortcut for
Forms!ThisForm.

In your case, since the code is in the form's own module, the code would
look something like:

DoCmd.OpenForm "frmRegistrations", acNormal,,,acFormAdd
Forms!frmRegistrations.SomeControl = Me.lname & " " & Me.fname
DoCmd.Close Me.Name

Just changeSomeControl to the name of the target control in
frmRegistrations.

HTH,
Nikos
 

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