Results 1 to 13 of 13

Thread: MsgBox

  1. #1
    Join Date
    May 2004
    Posts
    63

    Exclamation Unanswered: MsgBox

    How can i create custome msgbox for the PK ? For example i have CustID as PK and one record has CustID = 5 and if i enter new record with CustID=5 Access generates error. Insted of Access Generated Error how can i display custome msgbox ?

    Also, CustID should be 5 digit long.. how can check to see that user enters each any every req digit for CustID ?

    Thanks In Advance

  2. #2
    Join Date
    Apr 2004
    Location
    metro Detroit
    Posts
    634
    Are you trying to do this in a form?

  3. #3
    Join Date
    May 2004
    Posts
    63
    Forms and Table

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    If you would like a custom message box you could write code to manually check the length and validity of an unbound text box, then update the value in the table if the check passes. I don't know exactly what you're using this for so I'm not sure how feasable that would be.

    eg:
    Code:
    If Len(txtCustID) <> 5 Then
       MsgBox "Customer ID must be 5 characters long
    ElseIf DCount("CustID", "Customers", "CustID = " & txtCustID) Then
       MsgBox "This customer ID already exists"
    Else
       'actually update the value here.
    End If
    Last edited by Teddy; 05-12-04 at 14:01.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Apr 2004
    Location
    metro Detroit
    Posts
    634
    I'm not sure how or even if it can be done on the table (I don't think it can).

    On the form add code to the before update event of your CustID Control that checks the length and sets focus back to the CustID control if <> 5 (maybe pop up a msgbox here to tell the user that CustID must = 5 chars).

    To replace the default error message box you need to get the error number and set your own msgbox to come up on that error number. I think this would go in the before update event of the form.

  6. #6
    Join Date
    May 2004
    Posts
    63
    Teddy,

    DCount("CustID", "Customers", "CustID = " & txtCustID)

    What does customres reprsents ? Is it table name ?

    I'm getting error saying "Expected array"

  7. #7
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Yup, customers would be whatever table name you're looking in. DCount uses the following syntax:

    DCount(expr, domain, [criteria])
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  8. #8
    Join Date
    May 2004
    Posts
    63
    I'm still getting errror....I think its because of Dcount...Is Dcount built in function ?

  9. #9
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Yes it is.

    Post your whole sub please.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  10. #10
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    hi all,

    don't know where you've got to so far, but the last bit of code i saw included:

    ElseIf DCount("CustID", "Customers", "CustID = " & txtCustID) Then

    ...and the bad news is that DCOUNT() does not return TRUE/FALSE, it returns a number (the COUNT of matching records in the domain (or error!)).

    if you like cheating, this will work sometimes: A's FALSE= 0 = DCOUNT(no hits)

    ...meanwhile A's TRUE= -1 = unnatural return from DCOUNT()


    consider....


    dim myvar as long
    myvar = DCount("CustID", "Customers", "CustID = " & txtCustID)
    ...and play with myvar (=0, >0 etc)

    ---or---

    (else)if DCount("CustID", "Customers", "CustID = " & txtCustID) > 0 Then


    izy
    currently using SS 2008R2

  11. #11
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Cheating? Yes

    Will it work? Yes

    For instance, I ran this bit of code against a current operating DB:
    Code:
    If DCount("name", "Company", "name LIKE '%" & txtTest.Value & "%'") Then
        MsgBox "True"
    Else
        MsgBox "False"
    End If
    By inputing a value of a current company into the text box, I am able to generate either True, or False accordingly.

    It works just dandy.

    Now if you want to be a stickler, then go ahead with the > 0 route.

    Mr. Fancy Pants.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  12. #12
    Join Date
    May 2004
    Posts
    63

    Thumbs up

    Thanks

    If Dcount("CustID", "tblCustomer", "CustID = '" & Me.txtCustID & "'") > 0 Then
    MsgBox "This Cust ID already exists, Please enter new Cust ID for new Customer", vbInformation
    Cancel = True

    End If

    End Sub

  13. #13
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    hi Teddy,

    truth is relative (as always: check out the political situation almost anywhere these days), only false-ness has absolute meaning.

    A's definition is (...unofficial, this from my investigations so far):
    FALSE = 0
    not(TRUE) = not(not(FALSE))
    ...which gives an implied definition...
    TRUE = not(FALSE)

    ...but meanwhile...
    A also has a constant:
    TRUE = -1
    --which is certainly compatible with the above FALSE definition.
    --and is also compatible with the bitwise-NOT on 0 in 16-bit space with the top bit reserved for negative numbers

    so, yes, cheating works.
    check out some earlier posts from me about dates: i cheat all the time!

    izy


    hey - i forgive you for the Left() <> Left$()
    currently using SS 2008R2

Posting Permissions

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