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
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