Results 1 to 9 of 9
  1. #1
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568

    Get ID of Primary Key using VBA

    Hi,

    I have code within contonuos form with checkboxes:

    Code:
    Private Sub But_ok_Click()
    
    Dim rst As DAO.Recordset
    Dim counter As Byte
    Dim zmiennaPel As String
    Dim HowManyChecked As Boolean
    
    
    Set rst = Me.Recordset
    
    
    'Me.PivotTable.ActiveView.DataAxis.FieldSets(0).Fields(0).DetailBackColor = RGB(155, 155, 155)
    'Set PivotTable fieldsets
    
    
    rst.MoveLast
    rst.MoveFirst
    
    
    If DCount("Wybór", "QryKlientWew", "Wybór=True") > 1 Then
        MsgBox "Wybierz tylko jeden checkbox"
        Exit Sub
    End If
    
    
    Do While Not rst.EOF
        If IsChecked(rst!Wybór) = True Then
            Debug.Print ID_klient_slownik
        End If
    rst.MoveNext
    Loop
    
    
        'Form_frm_User.Txb_Zakres.Value = me.
    
    
    End Sub
    This form is build on the query "QryKlientWew" where i have:
    ID_klient_slownik -primary key - autonumber
    Pełnomocnictwo_nazwa - text
    Wybór - checkbox



    And now i want to get using VBA primary key for specific record where checkbox = true.

    How can i achive this ?

    Thank you,
    best Wishes,
    Jacek Antek

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    What primary key are you looking for? Is it the one for the record that the user is currently on?

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Wouldn't a DLookup() with the same criteria work?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Dlookup did the work !

    Thank you !

    But maybe there is some any other solutions ?

    Best Wishes,
    Jacek Antek

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sure, there are usually several ways to solve a problem. You could also use a recordset.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    pbaldy i was trying to use recordset but i can't refer to primary key.
    How you can do this ?

    Jacek

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You use an SQL statement with same criteria as the DLookup().
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Thank you !

    Best Wishes,
    Jacek

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem. I'd use the DLookup() for a single record/field, a recordset for multiples of either.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Help with primary key
    By JimmyRN in forum Database Design
    Replies: 10
    Last Post: 07-31-2017, 09:42 AM
  2. What is best for Primary key
    By tagteam in forum Access
    Replies: 3
    Last Post: 03-20-2013, 06:00 PM
  3. Primary key
    By Sara_IT in forum Access
    Replies: 2
    Last Post: 11-25-2011, 02:46 PM
  4. Primary Key Help
    By phoenix13 in forum Access
    Replies: 4
    Last Post: 07-30-2009, 12:36 PM
  5. about the primary key!
    By Yuesko in forum Access
    Replies: 1
    Last Post: 05-29-2009, 04:20 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