Save Record + Not Using The Wizard

dynamix

Registered User.
Local time
Today, 23:11
Joined
Feb 9, 2005
Messages
38
One thing I've noticed.. The wizard sucks!

I created a Save record button... But later had to change the name of that cmd button because of a code I wanted to add to it.

Now I have discovered that when you add code to a wizard created command button, it stops functioning.. Right?? (Or wrong :S)??

Well either way, I would like to create a command button that simply SAVES the record but I have some form validation coding and I need the validation coding to be executed on the click of the SAVE button. The coding is below:

Private Sub cmdSaveRec1_Click()
ConfirmEntries
End Sub


The question summarised:
The validation works and it runs the ConfirmEntries function, however it doesn't save the record.. How can I make it do both?


Thank you so, so, so much guys for any help at all. I appreciate it.
 
A little tip for the future: never use any of the code created by wizards in Access; it's years out of date.

As for saving a record, this is the current method:

Code:
DoCmd.RunCommand acCmdSaveRecord
 
While the code created by the wizards isn't the greatest, adding something to it won't make it stop working. It sounds like you changed the name of the button, so what probably happened is that the code formerly associated with that button isn't any longer (that will happen when you change the name). Just cut/paste the old code into the newer code.

Edit: sorry SJ, your post wasn't there when I started typing.
 
Thanks for your posts guys.. If its not Access producing the error, do you think you can help me out?

I have the following validation code setup to make sure no null values are entered:

Private Function ConfirmEntries() As Boolean
'Purpose: Checks whether entries have been made in the
'following textboxes and displays a message for any null
'values or empty boxes

If IsNull(Me.F_Name) Then
MsgBox "Please enter member F_Name"
F_Name.SetFocus
ConfirmEntry = True
Exit Function
End If
If IsNull(Me.L_Name) Then
MsgBox "Please enter member L_Name"
L_Name.SetFocus
ConfirmEntry = True
Exit Function
End If
If IsNull(Me.Address) Then
MsgBox "Please enter member Address"
Address.SetFocus
ConfirmEntry = True
Exit Function
End If
If IsNull(Me.PostCode) Then
MsgBox "Please enter member PostCode"
PostCode.SetFocus
ConfirmEntry = True
Exit Function
End If
If IsNull(Me.Tel) Then
MsgBox "Please enter member Tel"
Tel.SetFocus
ConfirmEntry = True
Exit Function
End If
If IsNull(Me.DOB) Then
MsgBox "Please enter member DOB"
DOB.SetFocus
ConfirmEntry = True
Exit Function
End If

End Function

Now, the code I was using to make the SAVE button (the access wizard generated SAVE button, remember ;)) call the above function was:
Private Sub cmdSaveRec1_Click()
ConfirmEntries
End Sub

So yeah, that now works, but i doesn't save the record nymore :S..

What can I do now that you know the scenario a little beter?

And thank you so much guys, I truely do appreciate this.
 
You need to use the BeforeUpdate event to prevent bad data from being saved. So, move the ConfirmEntries code to the form's BeforeUpdate event. Change all the "ConfirmEntry = True" statements to "Cancel = True" to cancel the update.

Then your save button only needs to save the record. That will cause the BeforeUpdate event to be run:

Private Sub cmdSaveRec1_Click()
DoCmd.RunCommand acCmdSaveRecord
End Sub
 
I found this thread as I was searching for an answer and followed roughly the instructions listed here but came across some roadblocks

I have 2subforms in 1 main forms. And I would like to delay all updates until I use the custom save button to save all 3 records. What I tried doing is as below to cancel all updates but it seems that I cannot move on to the next subform using this code

Private Sub Form_BeforeUpdate(Cancel As Integer)
Cancel = True
End Sub

Is there a way to get around it?

Pat and SJ, when it comes to using the code for saving as listed by yourselves, say if I had put the save button on the main form. When I click the save button, would that mean that even the subform records would be saved too??

Private Sub cmdSaveRec1_Click()
DoCmd.RunCommand acCmdSaveRecord (do i need to add more lines to save more records)
End Sub

Just wanted to drop a quick thanks to everyone in this forum, it has been tremendously helpful reading the posts and a great sharing and learning avenue!
 
Access saves records "quietly" in a number of situations. Since RI dictates that parent records exist prior to the addition of child records, the main form record is saved when focus is moved from the main form to the subform. Therefore, once that happens, there is no way to "undo" the mainform record, you must write code to actually delete it if you want it to go away. Same goes for when the cursor is moved from the subform back to the mainform or to a different subform (subform record is saved).

There are posts here on how to code around this but it gets complicated because you will probably need shadow tables. So you create an entire set of records in the temp tables and at some point press a button that automates the move to the real tables and deletes the data from the temp tables.
 
Thanks Pat, it was helpful to know the rationale about the referential integrity part. It now all makes sense why I cant move off the control of one form into a subform.

I guess I will use the Before update for each record for the time being and attempt the shadow tables when I have the time.

Appreciate your reply!
 

Users who are viewing this thread

Back
Top Bottom