Results 1 to 5 of 5
  1. #1
    joemills62 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    21

    Check if exsists

    Hi all

    I have a problem were dcount is reporting a false int, were in fact the data is in the table you will see that i have inserted msgbox to let me know ehat is happending.

    dcount should check the [directors] table to see if the contact exsists, if this is true then open a form in edit mode, if false then ask to add new record.

    however the dcount is coming up false when actually the contact does exsist



    Private Sub Command80_Click()
    Dim intChk As Boolean
    'If contact is TEXT
    MsgBox Me.[contact name]
    intChk = DCount("*", "directors", "[contact] = '" & Me.[contact name] & "'") > 0
    If intChk = True Then
    MsgBox intChk
    DoCmd.OpenForm "directors", acNormal, , , acFormEdit, acWindowNormal 'Edit Mode
    Else
    If intChk = False Then
    MsgBox intChk

    DoCmd.OpenForm "directors", acNormal, , , acFormAdd, acWindowNormal 'Add Mode
    End If
    End If

    End Sub

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You have verified the contact name is in the table? (..just asking )

    You will need to have a reference set for DOA, but try this:

    Code:
    Private Sub Command80_Click()
       Dim rs As DAO.Recordset
       Dim sSQL As String
    
       Dim blnChk As Boolean
    
       blnChk = False
    
       'If contact is TEXT
       '   blnChk = DCount("*", "directors", "[contact] = '" & Me.[contact name] & "'") > 0
    
       MsgBox Me.[contact name]
    
       sSQL = "SELECT contact FROM directors WHERE [contact] = '" & Me.[contact name] & "'"
       Set rs = CurrentDb.OpenRecordset(sSQL, , dbReadOnly)
       If Not rs.BOF And Not rs.EOF Then
          rs.MoveLast
          MsgBox rs.RecordCount
          blnChk = True
       End If
       rs.Close
       Set rs = Nothing
    
       If blnChk = True Then
          MsgBox blnChk
          DoCmd.OpenForm "directors", acNormal, , , acFormEdit, acWindowNormal   'Edit Mode
       Else
          'boolean can only be TRUE or FALSE. no need to check for FALSE since already checked for TRUE
          '      If blnChk = False Then
          MsgBox blnChk
          DoCmd.OpenForm "directors", acNormal, , , acFormAdd, acWindowNormal      'Add Mode
          '      End If
       End If
    
    End Sub

  3. #3
    joemills62 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    21
    I am still getting a false return, interesting enough though, when i done a query in the directors database, and i put in = quotes the directors name which is in the table, when ui run it it also comes up false ???

    Also the [contact] field is also a lookup field from the contact table, i wonder if this is the problem, and how could i correct it ?

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also the [contact] field is also a lookup field from the contact table, i wonder if this is the problem, and how could i correct it ?
    Yes, that is a huge problem.
    See "The Evils of Lookup Fields in Tables"


    at http://access.mvps.org/access/lookupfields.htm


    You are seeing a name, but the actual field type is probably a number (long integer).

  5. #5
    joemills62 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    21
    Yes this has been the problem all the time, thank you.
    would it be best then to use a form to add directors, but have the form look up the company table to select the company ?

    and if so, how would i go about it

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

Similar Threads

  1. check data if exsists the add new record
    By joemills62 in forum Programming
    Replies: 18
    Last Post: 06-13-2011, 04:39 PM
  2. Check for no value
    By jgelpi16 in forum Programming
    Replies: 12
    Last Post: 07-29-2010, 02:53 PM
  3. To check or Un-Check all Boxes in a form
    By devcon in forum Forms
    Replies: 7
    Last Post: 05-01-2010, 12:03 AM
  4. Check box
    By nashr1928 in forum Forms
    Replies: 5
    Last Post: 04-21-2010, 02:37 PM
  5. Check Box Value
    By mulefeathers in forum Programming
    Replies: 4
    Last Post: 10-09-2009, 08:31 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