To Save or Not To Save

G

Guest

I have a database which up to now hasn’t had a save button on the various
forms. I’m thinking I may need to add one so I handle various errors that are
happening.

First of all, what are people’s thoughts…..why have a save button? I’ve
tried some coding and you need to consider a lot of things to catch all
situations.

I’ve had a go at this and I’ve run into a few problems….my VB skills are
pretty poor.
One such problem is…..when I hit the save button I get the Before Update
MsgBox. See code below. How do I stop this?

Any help of advice would be appreciated.
Thanks in advance
Glenn


Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim lngrecordnum As Long

lngrecordnum = Me.CurrentRecord
If Me.NewRecord Then
Dim ctl As Control
Dim intMsgResponse As Integer
For Each ctl In Me.Controls
If ctl.Tag = "Required Field" Then
If ctl = "" Or IsNull(ctl) Then
Cancel = True
End If
End If
Next
If Cancel = True Then
MsgBox "Please complete all the required fields before you
continue.", vbOKOnly, "Information"
Else
If MsgBox("Do you want to save this Company record? ", vbYesNo,
"Question...") = vbYes Then
DoCmd.Save
Else
Me.Undo
End If
End If
Else
With Me.RecordsetClone
.Bookmark = Me.Bookmark
End With
If Me.Dirty = True Then
If MsgBox("Do you want to save your changes? ", vbYesNo,
"Question...") = vbYes Then
DoCmd.Save
Else
Me.Undo
End If
End If
End If
 
G

Guest

IMHO, Save buttons are pretty much a waste of time with bound forms. It is a
lot of coding for very little, if any, benefit. You will not be able to
avoid the Before Update event firing.
 
J

John Vinson

One such problem is…..when I hit the save button I get the Before Update
MsgBox. See code below. How do I stop this?

Well... yes.

Your save button causes the record to be saved. This action causes the
Form's BeforeUpdate event to be executed, because that's what you're
asking it to do - update the database.

One thing you can do is have a global variable. At the top of the
Form's Module, before any Sub lines, put

Public bOKToSave As Boolean

Set this value to False in the form's Current event, and to True in
the click event of the save button; check it in the form's
BeforeUpdate event to take appropriate action depending on whether the
user has clicked the save button or is doing something else to cause
the record to be saved.

John W. Vinson[MVP]
 
G

Guest

I always use save buttons, but then my customers are mechanics and the like,
and generally like everything self explanatory when it comes to their
software, without a save button I'd be getting 15 calls a day for the first
month or so. :p

TonyT..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top