Results 1 to 3 of 3
  1. #1
    J56789 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Apr 2016
    Posts
    2

    Problem with DCount


    Hi

    Im using this to code to try and only get the form to open when the number is present in the account number fied in the data table but it's bringing back 0 every time, ie giving me the message "Account number not found".
    Help please 😃

    Private Sub Command0_Click()

    DoCmd.SetWarnings False

    If IsNull(Me.Number.Value) Or (Me.Number.Value) = "" Then
    MsgBox "Please Enter Account Number"
    Exit Sub
    Else
    End If

    'If DCount("[Account_Number]", "Data", [Account_Number] = Me.Number) > 0 Then
    DoCmd.OpenForm FormName:="Form1"
    'Exit Sub
    'Else
    'End If

    'MsgBox "Account Number not found"
    'Exit Sub

    DoCmd.SetWarnings True
    End Sub

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    you have a few issues -

    Number is a reserved word so is likely to cause problems - see this link for reserved words

    https://support.office.com/en-us/art...7-da237c63eabe

    It also helps enormously when trying to debug code to allow warnings - so comment out your two setwarnings lines - it will not doubt then tell you why you are getting the 'not found' message

    If IsNull(Me.Number.Value) Or (Me.Number.Value) = "" Then
    a field or control called number is usually a number so cannot be text. Also FYI you do not need Me. or .Value since these are the defaults.

    'If DCount("[Account_Number]", "Data", [Account_Number] = Me.Number)
    the criteria should be expressed as

    "[Account_Number] = " & Me.Number

  3. #3
    J56789 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Apr 2016
    Posts
    2
    Hi thanks for replying.

    The first park works fine, giving the message if nothing is entered. And the not found message is one I've asked for if the DCount is 0.

    I changed the word to number for the post as the actual name of the text box would have made less sense 😃, so I'm not using reserved words.

    I'll try changing the criteria to that tomorrow.

    Cheers

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dcount Problem
    By drunkenneo in forum Programming
    Replies: 1
    Last Post: 11-11-2013, 05:42 AM
  2. Replies: 1
    Last Post: 10-18-2013, 02:17 PM
  3. Dcount Problem
    By sdel_nevo in forum Forms
    Replies: 1
    Last Post: 05-14-2013, 04:32 AM
  4. Module & dcount problem
    By gg80 in forum Modules
    Replies: 5
    Last Post: 01-20-2012, 07:12 PM
  5. DCount function problem
    By 10 Gauge in forum Forms
    Replies: 5
    Last Post: 02-28-2011, 02:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums