Results 1 to 6 of 6
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    754

    PCount issue once i changed tables/forms


    Hi all,
    I had to make some changes to my form I have this code (below) on and changed the PersonID to a CboPerson and not sure how to change the code that goes with it.
    I believe the AT = PersonID needs to be changed to CboPerson but cannot figure out what syntax goes with it?
    Thank you all

    Code:
    
    Private Sub CmdClose_Click()
        Dim pCount As Integer
        Dim TF As Boolean
        Dim AT As String
        AT = [PersonID]
        'Count number of Preferred=True for this PersonID
        pCount = DCount("PersonID", "Person2AddressTbl", "PersonID=" & AT & " AND Preferred =" & True)
        
        If pCount = 0 Then
            TF = True
        Else
            TF = False
        End If
        
    
    DoCmd.Close
    Forms!PersonFrm.Refresh
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    AT = Me.cboPerson

    Don't really need AT and PCount variables. A one-liner can set the TF variable.
    Code:
        'Count number of Preferred=True for this PersonID
        TF = (DCount("PersonID", "Person2AddressTbl", "PersonID=" & Me.CboPerson & " AND Preferred = True") = 0)
    What purpose does TF serve? You set it but don't do anything with it.
    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.

  3. #3
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    754
    Thanks June7,
    Thanks a lot,

    When i add an address if Preferred is not set, it sets it as true for that persons address, but if a preferred all ready exist, then it doesn't add the new address as Preferred.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Sorry, that doesn't make sense.

    The TF variable doesn't do anything. No field is set to anything.

    Perhaps you need:
    If Me.NewRecord Then
    Me!Preferred = (DCount("PersonID", "Person2AddressTbl", "PersonID=" & Me.CboPerson & " AND Preferred = True") = 0)
    End If
    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.

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    754
    Hi June7,
    I beleive you are correct. I dont think it ever did work like i wanted it to.
    What i was trying to accomplish was. The person can have mutipul addresses so when i add an address, if there is no preferred address, then it makes it preferred by ticking "Preferred" check box in table. If there is one all ticked, then do nothing. So basically there can only be one preferred address. I have code that works great if i change the preferred but this doenst work at all. Not real sure why i though it did to beging with?
    Thanks

  6. #6
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    754
    That worked really well June7, Thank you!
    Amazing

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

Similar Threads

  1. pCount to tick box is = 0
    By d9pierce1 in forum Programming
    Replies: 9
    Last Post: 08-11-2019, 05:10 PM
  2. Replies: 6
    Last Post: 09-10-2018, 12:11 PM
  3. Unmatched Query to find Changed info between tables
    By michael.p.ryan1 in forum Access
    Replies: 3
    Last Post: 08-24-2012, 02:22 PM
  4. Replies: 7
    Last Post: 03-22-2011, 10:36 AM
  5. Identifying Changed Fields in Two Tables
    By novice in forum Queries
    Replies: 1
    Last Post: 12-16-2010, 05:43 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