Having problem putting a Form _BeforeUpdate event (1 Viewer)

emsadoon

Registered User.
Local time
Today, 09:22
Joined
Jun 6, 2013
Messages
83
Hi,
I have On Load, Current, After Update events on a form, which all work fine. But, when I add a Before Update, I get the error: "Procedure declaration does not match description of event or procedure having the same name". Can anyone please help me to resolve this issue. Following is my code:


Code:
Private Sub Form_Load()
If InStr(Me.Filter, "=") > 0 Then
        If IsNumeric(Mid$(Me.Filter, InStr(Me.Filter, "=") + 1, Len(Me.Filter) - InStr(Me.Filter, "="))) Then
            Me.Tag = (Mid$(Me.Filter, InStr(Me.Filter, "=") + 1, Len(Me.Filter) - InStr(Me.Filter, "=")))
        End If
    End If
 
 
End Sub
 
Private Sub CmboMinute_AfterUpdate()
    Me.CollectionTime = Me.CmboHour & ":" & Me.CmboMinute
    Me.Refresh
End Sub
 
Private Sub Form_Current()
    Dim strTime As String
    Dim strHour As String
    Dim strMinute As String
    Dim intcolon As Integer
 
    If IsNull(CollectionTime.Value) Then
 
        Me.CmboHour = ""
        Me.CmboMinute = ""
 
    Else
 
        strTime = CollectionTime.Value
 
        intcolon = InStr(strTime, ":")
 
        If intcolon <= 0 Then Exit Sub
 
 
        strHour = Left$(strTime, intcolon - 1)
        strMinute = Right$(strTime, Len(strTime) - intcolon)
 
        Me.CmboHour = strHour
        Me.CmboMinute = strMinute
 
    End If
 
End Sub
 
Private Sub Form_BeforeUpdate()
MsgBox "Hello"
End Sub
 
' Change the status of the order to "Completed" once the remaining units = 0
Private Sub Form_AfterUpdate()
 
    Dim dbs As DAO.Database
    Dim rstTest As DAO.Recordset
    Dim strQuery As String
    Dim rstUpdate As DAO.Database
    Dim strQuery2 As String
    Dim db As Database
 
        strQuery = "SELECT OrderingT.Order_ID, OrderingT.UnitsRequested,OrderingT.OrderStatus, ([UnitsRequested])-Count([Product_ID]) AS [The Remaining Units] " + _
        "FROM (OrderingT INNER JOIN PackingSlipT ON OrderingT.Order_ID = PackingSlipT.Order_ID) INNER JOIN ProductT ON PackingSlipT.PackingSlip_ID = ProductT.PackingSlip_ID " + _
        "WHERE (PackingSlipT.PackingSlip_ID = " & Form.Tag & ") " + _
        "GROUP BY OrderingT.Order_ID, OrderingT.UnitsRequested , OrderingT.OrderStatus;"
 
 
        Set db = CurrentDb
 
        Set rstTest = db.OpenRecordset(strQuery)
 
    If Not rstTest.EOF Then
 
         If rstTest![The Remaining Units] = 0 Then
 
            MsgBox "This order was completely filled "
 
 
            strQuery2 = "UPDATE OrderingT " + _
            "SET OrderingT.OrderStatus = 'Completed' " + _
            "WHERE (((OrderingT.Order_ID)= " & [rstTest]![Order_ID] & " )); "
 
            db.Execute strQuery2
 
        End If
 
    End If
 
End Sub
 

CazB

Registered User.
Local time
Today, 13:22
Joined
Jul 17, 2013
Messages
309
I may be wrong here.... but could it not just be because you have a comment between two procedures (shown in red below)?

Code:
Private Sub Form_BeforeUpdate()
MsgBox "Hello"
End Sub
 
[COLOR=red]' Change the status of the order to "Completed" once the remaining units = 0[/COLOR]
Private Sub Form_AfterUpdate()
 

pr2-eugin

Super Moderator
Local time
Today, 13:22
Joined
Nov 30, 2011
Messages
8,494
BeforeUpdate method takes in an Argument.. Try..
Code:
Private Sub Form_BeforeUpdate([COLOR=Red][B]Cancel As Integer[/B][/COLOR])
I am intrigued by your usage of Form AfterUpdate.. Is that updating the table that the form is bound to? Or what is the use of the after update method here?
 

emsadoon

Registered User.
Local time
Today, 09:22
Joined
Jun 6, 2013
Messages
83
Thanks CazB and Paul . By the way, Paul's method worked perfectly. To your question Paul, I used After Update event to query for the total amount of products added to a specific order, and once the order is fully filled, the after update will change the status of the order, which is a field in the order table. Now, I want to use Before Update event to basically prevent the user to add more product once the order is fully filled. However, I am not sure if this is a good way. Please suggest me if you have better ideas regarding this matter.
 

Users who are viewing this thread

Top Bottom