Pop up a ? for the user, that they verify form data of a combo box

M

Michaelcip

Hello, I’d like to add code into my form’s “save record†button that asks the
user the question as to whether or not they intended to flag the “In
Warranty†or “Out of Warranty†combo box (that links to a yes/no field). The
current code on the “Save Record†button is:
___________________________________________
Private Sub cmdSaveRecord_Click()
On Error GoTo Err_cmdSaveRecord_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_cmdSaveRecord_Click:
Exit Sub

Err_cmdSaveRecord_Click:
MsgBox Err.Description
Resume Exit_cmdSaveRecord_Click

End Sub

_______________________________________________
What code goes where? Many thanks, Michael
 
A

Allen Browne

Use the BeforeUpdate event of the *form* to ask this question. There are
myriads of ways the record can be saved (not just clicking your button), and
Form_BeforeUpdate is the only way to catch them all.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
With Me.[In Warranty]
If (.Value = .OldValue) Or (Me.NewRecord) Then
'do nothing
Else
strMsg = "You changed Warranty. Intentional?"
If MsgBox (strMsg, vbYesNo, "Confirm") <> vbYes Then
Cancel = True
'Me.Undo
End If
End If
End With
End Sub

BTW, in your 'save record' button's code, it might be better to use this
line rather than the DoMenuItem:
If Me.Dirty Then RunCommand acCmdSaveRecord
 
M

Michaelcip

Thanks Allen. However, it seemed to’ve worked the opposite way that I had
hoped (I appologize for my lack of clarity). The message only popped up in
instances where I had altered the “Warrany/NotWarrantied†combo box. I want
the message to pop up if they somehow bypassed the field.
Also, the way your code works, it would seem that I don’t need the “save
record†button at all?! Your thoughts,…
Thanks, Michael


Allen Browne said:
Use the BeforeUpdate event of the *form* to ask this question. There are
myriads of ways the record can be saved (not just clicking your button), and
Form_BeforeUpdate is the only way to catch them all.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
With Me.[In Warranty]
If (.Value = .OldValue) Or (Me.NewRecord) Then
'do nothing
Else
strMsg = "You changed Warranty. Intentional?"
If MsgBox (strMsg, vbYesNo, "Confirm") <> vbYes Then
Cancel = True
'Me.Undo
End If
End If
End With
End Sub

BTW, in your 'save record' button's code, it might be better to use this
line rather than the DoMenuItem:
If Me.Dirty Then RunCommand acCmdSaveRecord

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Michaelcip said:
Hello, I’d like to add code into my form’s “save record†button that asks
the
user the question as to whether or not they intended to flag the “In
Warranty†or “Out of Warranty†combo box (that links to a yes/no field).
The
current code on the “Save Record†button is:
___________________________________________
Private Sub cmdSaveRecord_Click()
On Error GoTo Err_cmdSaveRecord_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_cmdSaveRecord_Click:
Exit Sub

Err_cmdSaveRecord_Click:
MsgBox Err.Description
Resume Exit_cmdSaveRecord_Click

End Sub

_______________________________________________
What code goes where? Many thanks, Michael
 
A

Allen Browne

I you are just worried about it being left blank, just test if it is null:
If IsNull(Me.[In Warranty]) Then
...

I don't understand that for a yes/no field though, as a yes/no field in a
JET table (the tables built into Access) cannot be Null.

Quite correct: you don't need your save button.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Michaelcip said:
Thanks Allen. However, it seemed to’ve worked the opposite way that I had
hoped (I appologize for my lack of clarity). The message only popped up
in
instances where I had altered the “Warrany/NotWarrantied†combo box. I
want
the message to pop up if they somehow bypassed the field.
Also, the way your code works, it would seem that I don’t need the “save
record†button at all?! Your thoughts,…
Thanks, Michael


Allen Browne said:
Use the BeforeUpdate event of the *form* to ask this question. There are
myriads of ways the record can be saved (not just clicking your button),
and
Form_BeforeUpdate is the only way to catch them all.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
With Me.[In Warranty]
If (.Value = .OldValue) Or (Me.NewRecord) Then
'do nothing
Else
strMsg = "You changed Warranty. Intentional?"
If MsgBox (strMsg, vbYesNo, "Confirm") <> vbYes Then
Cancel = True
'Me.Undo
End If
End If
End With
End Sub

BTW, in your 'save record' button's code, it might be better to use this
line rather than the DoMenuItem:
If Me.Dirty Then RunCommand acCmdSaveRecord

Michaelcip said:
Hello, I’d like to add code into my form’s “save record†button that
asks
the
user the question as to whether or not they intended to flag the “In
Warranty†or “Out of Warranty†combo box (that links to a yes/no
field).
The
current code on the “Save Record†button is:
___________________________________________
Private Sub cmdSaveRecord_Click()
On Error GoTo Err_cmdSaveRecord_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

Exit_cmdSaveRecord_Click:
Exit Sub

Err_cmdSaveRecord_Click:
MsgBox Err.Description
Resume Exit_cmdSaveRecord_Click

End Sub

_______________________________________________
 
M

Michaelcip

I was able to work w/ what you sent me prior. Thank-you so much for your
time; all the best, Michaelcip

Allen Browne said:
I you are just worried about it being left blank, just test if it is null:
If IsNull(Me.[In Warranty]) Then
...

I don't understand that for a yes/no field though, as a yes/no field in a
JET table (the tables built into Access) cannot be Null.

Quite correct: you don't need your save button.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Michaelcip said:
Thanks Allen. However, it seemed to’ve worked the opposite way that I had
hoped (I appologize for my lack of clarity). The message only popped up
in
instances where I had altered the “Warrany/NotWarrantied†combo box. I
want
the message to pop up if they somehow bypassed the field.
Also, the way your code works, it would seem that I don’t need the “save
record†button at all?! Your thoughts,…
Thanks, Michael


Allen Browne said:
Use the BeforeUpdate event of the *form* to ask this question. There are
myriads of ways the record can be saved (not just clicking your button),
and
Form_BeforeUpdate is the only way to catch them all.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
With Me.[In Warranty]
If (.Value = .OldValue) Or (Me.NewRecord) Then
'do nothing
Else
strMsg = "You changed Warranty. Intentional?"
If MsgBox (strMsg, vbYesNo, "Confirm") <> vbYes Then
Cancel = True
'Me.Undo
End If
End If
End With
End Sub

BTW, in your 'save record' button's code, it might be better to use this
line rather than the DoMenuItem:
If Me.Dirty Then RunCommand acCmdSaveRecord

Hello, I’d like to add code into my form’s “save record†button that
asks
the
user the question as to whether or not they intended to flag the “In
Warranty†or “Out of Warranty†combo box (that links to a yes/no
field).
The
current code on the “Save Record†button is:
___________________________________________
Private Sub cmdSaveRecord_Click()
On Error GoTo Err_cmdSaveRecord_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

Exit_cmdSaveRecord_Click:
Exit Sub

Err_cmdSaveRecord_Click:
MsgBox Err.Description
Resume Exit_cmdSaveRecord_Click

End Sub

_______________________________________________
 

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