Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    joemills62 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    21

    check data if exsists the add new record

    I have a button on contact details form to view director details



    I want the button to check

    1, check to see if the director is in the database
    2, if not ask if you want to add to directors table using form directors
    3, if yes add record using the form
    4, if no, return

    i am using the following code

    Dim intChk As Integer

    intChk = DCount("*", "directors", "[contact] = '" & Forms!contact_details![contact name] & "'") > 0

    but im getting an error

    runtime error '3464' data type mismatch in expression

    can anyone help me this codeing please

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try changing this one line:
    Dim intChk As Integer
    ...to...
    Dim intChk As Boolean

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Dim intChk As Boolean
    Not to be a nit picker, you might also think about:

    Dim blnChk As Boolean

    if this is a local variable.... (just to keep things consistent)

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Good point.

  5. #5
    joemills62 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    21
    Many thanks,
    I have changed to var to blnchk to boolean and still get same error

    the code is now
    Private Sub Command80_Click()
    Dim blnChk As Boolean
    ' contact is TEXT
    intChk = DCount("*", "directors", "[contact] = '" & Forms!contact_details![contact name] & "'") > 0
    If blnChk = True Then
    DoCmd.OpenForm "directors", acNormal, , , acFormEdit, acWindowNormal 'Edit Mode
    Else
    If Me.Dirty = True Then Me.Dirty = False 'Save pending Edits
    DoCmd.OpenForm "directors", acNormal, , , acFormAdd, acWindowNormal 'Add Mode
    End If

    End Sub

  6. #6
    joemills62 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    21
    sorry the code is now

    Private Sub Command80_Click()
    Dim blnChk As Boolean
    'If contact is TEXT
    blnChk = DCount("*", "directors", "[contact] = '" & Forms!contact_details![contact name] & "'") > 0
    If blnChk = True Then
    DoCmd.OpenForm "directors", acNormal, , , acFormEdit, acWindowNormal 'Edit Mode
    Else
    If Me.Dirty = True Then Me.Dirty = False 'Save pending Edits
    DoCmd.OpenForm "directors", acNormal, , , acFormAdd, acWindowNormal 'Add Mode
    End If

    End Sub

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Alright then is the [contact] field a text field?

  8. #8
    joemills62 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    21
    Yes, the contact field is a Text Field

    The idea is that it will check the directors table to see if this "director" exsists.

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You have both a Form and a Table named "directors"? Is this code on the contact_details form?

  10. #10
    joemills62 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    21
    yes, it is a button on the contact_details form, called directors details, when the button is pressed.
    1. it should check to see if the conatct name on the conatct details form exsists in the directors table, and if not option to add new record, or edit if exsiss

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I repeat:
    Quote Originally Posted by RuralGuy View Post
    You have both a Form and a Table named "directors"?
    ...and you do not need to go through the Forms collection:
    blnChk = DCount("*", "directors", "[contact] = '" & Me.[contact name] & "'") > 0
    This *IS* the line of code that is throwing the error, right?

  12. #12
    joemills62 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    21
    Yes, this is the code that is causing the error.

    I have copied what you have posted and seem to get the same error

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    To what is the [contact name] control bound? You might try a:
    MsgBox Me.[contact name] just before the DCount line to see what is in there.

  14. #14
    joemills62 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    21
    It is bound from the form contact_details [conatct name] field - > directors [contact]

    in debug mode it have appears to have the correct information eg. the directors name

    I put msgbox before the dcount,
    and it come up as the directs name which is correct

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    And you do have both a Form *and* a Table name "directors", right?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. VBA loop to check data
    By Cheshire101 in forum Programming
    Replies: 2
    Last Post: 05-02-2011, 08:39 AM
  2. check textbox1 on each record of report
    By sconard in forum Access
    Replies: 8
    Last Post: 04-13-2011, 12:26 PM
  3. Check multiple data
    By carstenhdk in forum Access
    Replies: 1
    Last Post: 05-05-2010, 10:19 AM
  4. Replies: 9
    Last Post: 04-27-2010, 01:00 PM
  5. Apply check at record level
    By wasim_sono in forum Programming
    Replies: 1
    Last Post: 04-19-2007, 07:48 AM

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