Results 1 to 10 of 10
  1. #1
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Warn User Message (2003)

    I have a form which allows a user to add a new purchase order. Basically, I have a table with the following two key fields, PurchaseOrder_ID and PurchaseOrder_Num. I have additional fields, but these are the key fields. I'd like to at least warn the user that the PurchaseOrder_Num field has been used previously, but they have the option to continue or cancel. Is this possible? Any input would be much appreciated. Thanks in advance.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Warn User Message (2003)

    Is PurchaseOrder_ID unique? If so, you could put code in the Before Update event of PurchaseOrder_Num:

    Private Sub PurchaseOrder_Num_BeforeUpdate(Cancel As Integer)
    If DCount("*", "NameOfTable", "PurchaseOrder_ID <> " & Me.PurchaseOrder_ID " & _
    " AND PurchaseOrder_Num = " & Me.PurchaseOrder_Num) > 0 Then
    Cancel = (MsgBox("This purchase order number has already been used. Continue anyway?", _
    vbQuestion + vbYesNo + vbDefaultButton2) = vbNo)
    End If
    End Sub

    Substitute the correct names.

  3. #3
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Warn User Message (2003)

    Hi Hans,

    I get a Compile Error, Syntax Error and it highlights the if statement.

    Private Sub PurchaseOrder_Num_BeforeUpdate(Cancel As Integer)
    If DCount("*", "PurchaseOrders", "PurchaseOrder_ID <> " & Me.PurchaseOrder_ID " & _
    " AND PurchaseOrder_Num = " & Me.PurchaseOrder_Num) > 0 Then
    Cancel = (MsgBox("This purchase order number has already been used. Continue anyway?", _
    vbQuestion + vbYesNo + vbDefaultButton2) = vbNo)
    End If
    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Warn User Message (2003)

    Sorry, there's an error in the code I posted. Change

    If DCount("*", "PurchaseOrders", "PurchaseOrder_ID <> " & Me.PurchaseOrder_ID " & _

    to

    If DCount("*", "PurchaseOrders", "PurchaseOrder_ID <> " & Me.PurchaseOrder_ID & _

  5. #5
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Warn User Message (2003)

    I should have posted this originally, but I just realized the field is a text field, and not a number field. I noticed some PO's actually have text, so I had to use a text field. Does this change the statement at all?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Warn User Message (2003)

    Which one is a text field? The _ID, the _Num, or both?

  7. #7
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Warn User Message (2003)

    just the PurchaseOrder_Num. The _ID is automatically generated, autonumber".

  8. #8
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Warn User Message (2003)

    I tried the revised code, and I get a Run-time error ' 3464': Data type mismatch in criteria expression.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Warn User Message (2003)

    Try this version. Chr(34) is the double quote character ".

    Private Sub PurchaseOrder_Num_BeforeUpdate(Cancel As Integer)
    If DCount("*", "PurchaseOrders", "PurchaseOrder_ID <> " & Me.PurchaseOrder_ID & _
    " AND PurchaseOrder_Num = " & Chr(34) & Me.PurchaseOrder_Num & Chr(34)) > 0 Then
    Cancel = (MsgBox("This purchase order number has already been used. Continue anyway?", _
    vbQuestion + vbYesNo + vbDefaultButton2) = vbNo)
    End If
    End Sub

  10. #10
    2 Star Lounger
    Join Date
    Mar 2002
    Posts
    164
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Warn User Message (2003)

    Excellent! Thank you sooo much as always!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •