add a seconday function to an existing command button

SirStevie3

Registered User.
Local time
Today, 14:14
Joined
Jul 29, 2013
Messages
58
I have a command button that basically saves the record that i just finished entering. here's the code:

Private Sub cmdAddAnother_Click()
On Error GoTo Err_cmdAddAnother_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
Exit_cmdAddAnother_Click:
Exit Sub
Err_cmdAddAnother_Click:
MsgBox Err.Description
Resume Exit_cmdAddAnother_Click
End Sub

honestly i dont know what it is doing exactly... i copied and pasted from the internet somewhere.

what i'd like to do now is add a second function that will make all the controls on the form go to null after the record is saved. so the user can start from scratch and add another record.

i tried adding me.refresh right before "end sub" but that didnt work.

i tried adding "me.controlname.value = null" for every control on the form, and that didnt work either.

i also tried adding this code that i found on bytes.com:
On Error Resume Next

Dim ctl As Control
For Each ctl In Me.Controls
ctl.Value = Null
Next

that didnt work either.

anyone have any suggestions? peas and carrots!
 
How about this?
Code:
Private Sub cmdAddAnother_Click()
On Error GoTo Err_cmdAddAnother_Click
    DoCmd.RunCommand acCmdSaveRecord 
    DoCmd.GoToRecord Record:=acNewRec
    
Exit_cmdAddAnother_Click:
    Exit Sub
Err_cmdAddAnother_Click:
    MsgBox Err.Description
    Resume Exit_cmdAddAnother_Click
End Sub
 
All you need to do, to Save the Current Record and go to a New Record, is go to a New Record! Access automatically Saves a Record when you leave it, whether you go to a New or other Record, Close the Form, or Close Access itself. All you need is

Code:
Private Sub cmdAddAnother_Click()
  DoCmd.GoToRecord , , acNewRec
End Sub
This goes to a new, blank Record, saving the Current Record in the process.

Linq ;0)>
 
Thanks guys! both suggestions worked perfectly.

i guess i was making it more complicated than it needed to be. im certainly aware that going to a new record saves the old one... i guess i just had a brain fart!!

thanks again to the both of you.
 
Don't feel bad; everybody here suffers from that affliction, at one time or the other! :D

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom