Results 1 to 8 of 8
  1. #1
    Bkndbrown is offline Novice
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    22

    lookup code

    I am sure this is easy but it is kicking my butt. I have a text box called SearchID I want it to count entries in SponsorDataT, field called LastINILast4SSN. If there are any matches open a record with that record if not open a new record. Sorry if code is messed up had to go computer to phone to here. Stupid firewall.

    Private Sub Command13_Click()
    If DCount("[LastINILast4SSN]", "[SponsorDataT]", "Forms![OpeningF]![SearchID]") < 0 Then
    DoCmd.OpenForm "SponsorDataSF", acNormal, "", "", acAdd, acNormal


    DoCmd.GoToRecord , , acNewRec

    Else
    DoCmd.OpenForm "SponsorDataSF", acNormal, "", "", acEdit, acNormal
    DoCmd.SearchForRecord acForm, "SponsorDataSF", acFirst, "LastINILast4SSN = '" & Forms!OpeningF!SearchID & "'"
    End If
    End Sub

  2. #2
    Bkndbrown is offline Novice
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    22
    Sorry forgot when I run it I get the same result whether there is a match or not so it isnt actually counting

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    The filter criteria needs field specified to match against.

    If DCount("*", "[SponsorDataT]", "ID=Forms![OpeningF]![SearchID]") < 0 Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Bkndbrown is offline Novice
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    22
    That caused a run time error 2471

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    What is the exact error message?

    Did you use your actual field name for ID?

    Why <0? Why not =0?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Bkndbrown is offline Novice
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    22
    Just realized I fat fingered a letter. It was =0 I changed it trying to figure what answer I was getting. Changed it back after posting. Yhanks

  7. #7
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    Quote Originally Posted by Bkndbrown View Post
    I am sure this is easy but it is kicking my butt. I have a text box called SearchID I want it to count entries in SponsorDataT, field called LastINILast4SSN. If there are any matches open a record with that record if not open a new record. Sorry if code is messed up had to go computer to phone to here. Stupid firewall.

    Private Sub Command13_Click()
    If DCount("[LastINILast4SSN]", "[SponsorDataT]", "Forms![OpeningF]![SearchID]") < 0 Then
    DoCmd.OpenForm "SponsorDataSF", acNormal, "", "", acAdd, acNormal
    DoCmd.GoToRecord , , acNewRec

    Else
    DoCmd.OpenForm "SponsorDataSF", acNormal, "", "", acEdit, acNormal
    DoCmd.SearchForRecord acForm, "SponsorDataSF", acFirst, "LastINILast4SSN = '" & Forms!OpeningF!SearchID & "'"
    End If
    End Sub
    If DCount("[LastINILast4SSN]", "[SponsorDataT]", "LastINILast4SSN = '" & Forms!OpeningF!SearchID & "'") = 0 Then

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    This expression should work either way because Access will be able to evaluate the control reference using the Forms collection prefix even if it is within quote marks. I was quite surprised the first time I encountered this. Now if you use Me. alias instead, that would require concatenation.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 4
    Last Post: 07-28-2015, 10:14 AM
  2. Replies: 3
    Last Post: 05-08-2015, 11:08 AM
  3. Replies: 5
    Last Post: 11-24-2014, 02:19 PM
  4. Display lookup value in form, not code.
    By lggerhard in forum Forms
    Replies: 2
    Last Post: 09-10-2014, 06:57 PM
  5. Replies: 5
    Last Post: 06-25-2014, 09:19 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