Link to home
Start Free TrialLog in
Avatar of cssc1
cssc1Flag for United States of America

asked on

Simple Code to Save All Objects

I am looking for simple vba code to:
1.  save all data on all objects on frmOne to Table1
2. Close frmOne
3. Open frmTwo
4. Refresh data on formTwo

This to be put on the click event of Command1 and Command2.
Code that I can easily modify and use on other forms/Cmmand buttons.

Sample db is attached to work with.

No macros
Test-OpenClose.accdb
SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cssc1

ASKER

imnorie:
  I can't get code to work?
Please see attached db
Test-OpenClose-VER2.accdb
Avatar of Norie
Norie

It should be Me.Name not Me.<form name>.

Me refers to the form but to close it using this method we need it's name.
Avatar of cssc1

ASKER

What did I do wrong now?

Private Sub Command9_Click()
    DoCmd.Close acForm, frmOne.Name
End Sub
<What did I do wrong now?>

We can't tell, because you didn't tell us what happened. We're not sitting in front of your machine, so we can't see what's going on - you have to tell use what happened (and perhaps show us a screenshot), and then we can help you to fix it.

I'd also avoid wording your questions as if they were project requirements and we were employees assigned to complete this task (for free, since we're not paid for any of this). This rubs many Experts the wrong way (me included) and can get your questions ignored by many of the top level Experts here.
Avatar of cssc1

ASKER

LSMConsulting:
  Sorry for my very poor wording of my questions. I did not mean to create and problems by my poor wording.

The problem I am having with the code:

Private Sub Command9_Click()
    DoCmd.Close acForm, frmOne.Name
End Sub


is this code should close frmOne and it is not doing that.
Please advise.

Thanks
Where did you put that code?

It should be in the module for the form.

Try this:

1 Open frmOne in design view.

2 Select the command button.

3 In the properties sheet under the Event tab you'll find OnClick (or Click), select it.

4 Click the dropdown on the right, choose [Event Procedure].

5 Then click the ellipsis ... and you should now see this:

Private Sub Command9_Click()

End Sub

6 This is where the code to close the form should go.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry:

DoCmd.Close acForm, "frmOne"
Avatar of cssc1

ASKER

LSMConsulting:
  Thanks, this code closes frmOne GREAT.

Woulkd this be the  code to open frmTwo?


Private Sub Command41_Click()
DoCmd.Close acForm, "frmOne"
DoCmd.Open acForm, "frmTwo"
End Sub

????
Docmd.OpenForm "frmTwo"
What happened to using Me.Name?

If the code was in  frmOne then Me.Name would equal 'frmOne'.