newbie question: two actions for a command button (1 Viewer)

Cyberslam

Registered User.
Local time
Today, 12:28
Joined
Sep 1, 2005
Messages
35
Hi all,

I am really new to designing forms in Access and something came up while designing one.

I have a form with different fields and theres a command button(save record) whose action is to save the record but i want to add another action to the same button which will open up a form.

Is this possible? If yes, how?

Thanks
 
M

Mike375

Guest
With either code or macro you can have heaps and heaps of actions occurring one after the other and opening a form is one of them.

However, you won't be able to do that from the Command button wizard. You gotta make 'em yourself:)

Code opens a form with

DoCmd.OpenForm "FormName", acNormal, "", "", , acNormal

For a macro use OpenForm action.

That should get you going.
 

Cyberslam

Registered User.
Local time
Today, 12:28
Joined
Sep 1, 2005
Messages
35
With either code or macro you can have heaps and heaps of actions occurring one after the other and opening a form is one of them.

However, you won't be able to do that from the Command button wizard. You gotta make 'em yourself:)

Code opens a form with

DoCmd.OpenForm "FormName", acNormal, "", "", , acNormal

For a macro use OpenForm action.

That should get you going.

Thanks Mike for replying.

So you mean i add two actions i.e.save & open form in a macro and then add the command button as a macro. Is it correct?
 
M

Mike375

Guest
No. The Command button is just one thing that can run code or a macro.

Go into form design and click on your button with the right clicker and then Properties and then Events. All those events you see will run code or a macro. You see things like OnClick (Obvious) LostFocus and so on.

If you right click on one of your fields in form design you will see it also has lots of events. If you make a label from the tool box (as distinct from a label that shows when you drag a field to the form) that also has lots of events. If you right click on the area of form design that is outside your actual form you will again see lots of events.

When you bring up Events from Properties then click on the line for OnClick and you will see a drop down arrow appear and just to the right of the arrow is 3 dots. The line with the arrow is where a macro name is written. The drop down arrow lists your macros.

If you click on the 3 dots a box will open and one of the options is Code Builder. That is where code is added. When you go to code builder a screen will open and you will see

Private Sub Text133_Click()

End Sub

The code goes in between. Private...means it is only for here.....modules have code that can be called from queries or within other code. Text133 is the textbox the code is attached to and Click() is obvious

Private Sub Text133_Click()

DoCmd.OpenForm "FormName", acNormal, "", "", , acNormal

End Sub

will open that form.

Many of the answers you see on this forum a for code to be added just as the code top open that form is shown.

This would open a form where it matched the record on the form from where you ran the code

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm "SumPremAllCats", acNormal, "", "([NameNumber]=[Forms]![MasterForm]![NameNumber])", acEdit, acNormal


It is saving the record....it is doing that because a related form is being opened......
It opens a from called SumPremAllCats where the NameNumber field in SumPremAllCats equals the NameNumber field on the form MasterForm, the form from where the code was run

All these type of things are also run by macro actions. I am one of the few people on the forum that is an extensive macro user. As such it pays you to know how to enter code because most answers will be code.
 

Cyberslam

Registered User.
Local time
Today, 12:28
Joined
Sep 1, 2005
Messages
35
Mike, thanks a lot for the detail explanation on how the macros works. Really appreciate it!

So what i understand from post is that i just have to add the below code in blank command button onclick event. Is it correct or am i still not getting something ?:eek:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm "FormName", acNormal, "", "([NameNumber]=[Forms]![MasterForm]![NameNumber])", acEdit, acNormal

I tried using Macros actions and it seems to be working as well. Btw, aren't records saved automatically in access without the need to press save record button?
 
M

Mike375

Guest
If you typed something in a field and then click on a label that runs a macro or code to open another form, then where you were typing is not saved at that point. If the form being opened is a related record and you make and entry on that that form, then closing that form you will get record locking.

So what i understand from post is that i just have to add the below code in blank command button onclick event. Is it correct or am i still not getting something ?

And obviously change the form/field names to your own.

But if you want to open the form and display all records then

DoCmd.OpenForm "FormName", acNormal, "", "", , acNormal

If using OpenForm for a related record in macro then

[NameNumber]=[Forms]![MasterForm]![NameNumber] goes in Where at the bottom of the screen.
 
R

Rich

Guest
, aren't records saved automatically in access without the need to press save record button?

Only if you move to new record or another form or move to a subform from the main form and visa versa
 

Users who are viewing this thread

Top Bottom