How to set two operations assigned to one button? (1 Viewer)

Lasidu Chamikara

New member
Local time
Today, 10:43
Joined
Apr 9, 2020
Messages
6
Hii, in my database, after entering required data in designed fields in a form, I want to display a message box as well as add those records to the relevant table at the same time. How can I perform this using a single button not with two separate buttons?
 

isladogs

MVP / VIP
Local time
Today, 06:13
Joined
Jan 14, 2017
Messages
18,212
Just add both items to the button click event procedure.
You may need a DoEvents line after the first item to ensure processing is completed before the second item.
Suggest the message box is the second item as code stops until the OK button is clicked
 

Lasidu Chamikara

New member
Local time
Today, 10:43
Joined
Apr 9, 2020
Messages
6
Thank you very much for replying.
I'm not very much good on Access, just a beginner. Here what I actually want to happen; there is an "Add Record" button in my form and when the user clicks it, I want to add the record as well as display a message box consisting what he has entered. Can you please further explain how to add those two functions to button click event procedure..?
 

isladogs

MVP / VIP
Local time
Today, 06:13
Joined
Jan 14, 2017
Messages
18,212
It sounds like you are using an unbound form which makes for a lot of unnecessary work.
If you have a bound form, data is saved automatically (though validation checks can be applied first)

Anyway if you have an unbound form, you can use code like
Code:
CurrentdB.execute "INSERT INTO YourTableName VALUES FieldName1='" & me.txtField1 & "', .... "

After that add your message box code e.g.
Code:
MsgBox "You have just added a record to table YourTableName"
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:13
Joined
Feb 19, 2002
Messages
43,257
Common convention is for an "Add" button to open up an empty form in which to add a new record. Then a "Save" button can be used to save it. You seem to be using the "Add" button to mean save. That will be confusing to people.

Also, in almost all cases, Add and Update should be done with the same form. You might need some custom code that looks at the NewRecord property to do some things only for new records and others only for existing records but generally, the validation rules for a field would be the same whether the record is being added or changed.

When you click on an event property, do you get a prompt that asks you if you want to use code or macro? I always use code as do most developers. Newbees think macros are easier but only for very simple things. Macro logic for anything complex is bizarre to put it gently.

Whether you are using macros or writing code, you can always perform multiple actions in ANY procedure.
 

Users who are viewing this thread

Top Bottom