cssc1
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
Me refers to the form but to close it using this method we need it's name.
ASKER
What did I do wrong now?
Private Sub Command9_Click()
DoCmd.Close acForm, frmOne.Name
End Sub
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.
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.
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
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry:
DoCmd.Close acForm, "frmOne"
DoCmd.Close acForm, "frmOne"
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
????
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'.
If the code was in frmOne then Me.Name would equal 'frmOne'.
ASKER
I can't get code to work?
Please see attached db
Test-OpenClose-VER2.accdb