By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,202 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

Un

P: n/a
I am trying to verify that orders already billed are changed in a
database. I have tried to execute the following code in before update,
and although the correct message box appears, the changed value remains
in the list box whereas I want it to go back to the original value
entered.

Private Sub Combo20_BeforeUpdate(Cancel As Integer)
Call OrderEntry

End Sub
Public Function OrderEntry()
If IsNull(Forms!OrderForm![Date Out]) Then
Forms!OrderForm![Date Out] = Date
Forms!OrderForm![Time Out] = Time
Else
If Forms!OrderForm![Date Out] < DateSerial(Year(Date),
Month(Date), 4) Then
MsgBox ("You have already billed for this order. Please
submit another entry for correction if needed")
Me.Service.Undo

Cancel = True

Else
If (MsgBox("You have already entered order this month, do
you wish to update it with new billing date?", vbYesNo) = vbYes) Then
Forms!OrderForm![Date Out] = Date
Forms!OrderForm![Time Out] = Time
Else
Forms!OrderForm![Date Out].Undo
Forms!OrderForm![Time Out].Undo
End If
End If
End If

End Function

Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Th**************@yahoo.com wrote:
I am trying to verify that orders already billed are changed in a
database. I have tried to execute the following code in before update,
and although the correct message box appears, the changed value remains
in the list box whereas I want it to go back to the original value
entered.

Private Sub Combo20_BeforeUpdate(Cancel As Integer)
Call OrderEntry

End Sub
Public Function OrderEntry()
If IsNull(Forms!OrderForm![Date Out]) Then
Forms!OrderForm![Date Out] = Date
Forms!OrderForm![Time Out] = Time
Else
If Forms!OrderForm![Date Out] < DateSerial(Year(Date),
Month(Date), 4) Then
MsgBox ("You have already billed for this order. Please
submit another entry for correction if needed")
Me.Service.Undo

Cancel = True

Else
If (MsgBox("You have already entered order this month, do
you wish to update it with new billing date?", vbYesNo) = vbYes) Then
Forms!OrderForm![Date Out] = Date
Forms!OrderForm![Time Out] = Time
Else
Forms!OrderForm![Date Out].Undo
Forms!OrderForm![Time Out].Undo
End If
End If
End If

End Function

Do you requery the combo? You can do so in the afterupdate event.
Me.Combo20.Requery
If the record has been saved, this will not help.
Nov 13 '05 #2

P: n/a
You're setting cancel=True outside of the procedure that contains the
cancel variable.

You need the OrderEntry function to return a boolean value which can
then be used to set cancel. For example;

Private Sub Combo20_BeforeUpdate(Cancel As Integer)
Cancel = OrderEntry
End Sub

Public Function OrderEntry() As Boolean
OrderEntry = False
IF blah = blah Then 'you want to cancel
OrderEntry = True
End If
End Function

There are probably better ways of doing it by passing the cancel
variable to the orderentry function instead of using the orderentry
variable to set cancel, but this will do.

HTH

Nov 13 '05 #3

P: n/a
Thanks that worked perfectly!

Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.