Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: Populating a sub form with a value

  1. #1
    Board Regular
    Join Date
    Dec 2008
    Posts
    111
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Populating a sub form with a value

    Hi all

    I am using Access 2016 and an ODBC link to an SQL Database.

    I have a form called "Search" which returns values into two sub forms ServiceUsersSearchList for current clients and TerminatedSericUsersSearch for former clients.

    The results show ClientID, Address1, Address2, Postcode from table dbo_Voids the user clicks on the row and clicks on AddRent button.

    This opens up a form called Rents where there is a field called ClientID from table dbo_rents, The two clientIDs are linked. What I would like is for the ClientID from the search to prepopulate on the Rents form.

    I am using the following code:

    Private Sub AddRent_Click()
    On Error GoTo Err_AddRent_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "Rents"
    stLinkCriteria = "[ClientID]=" & Me![ClientID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria


    Exit_AddRent_Click:
    Exit Sub
    Err_AddRent_Click:
    MsgBox Err.Description
    Resume Exit_AddRent_Click


    End Sub

    Any help greatly appreciated.
    thanks
    Andrew

  2. #2
    Board Regular
    Join Date
    May 2013
    Posts
    456
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Populating a sub form with a value

    I do it with OpenArgs

    Calling form button
    Code:
    Private Sub cmdProgress_Click()
    DoCmd.OpenForm "frmProgress", , , "CadetIDFK=" & Me.CadetID, , acDialog, Me.CadetID
    End Sub
    Called Form
    Code:
    Private Sub Form_Current()
    If Me.NewRecord Then
        Me.CadetIDFK = Me.OpenArgs
    End If
    End Sub
    
    So if records exists for the ID, I just get to see them. If none exist then the ID is populated correctly for the new record
    
    HTH
    Excel 2007

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •