Linking records in two tables using a command button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luciegiles
    New Member
    • Oct 2007
    • 56

    Linking records in two tables using a command button

    Hi,

    I am creating a database in which users will enter details for one client (record) in several tables via several associated forms. I would like to have a button on each form that takes the user directly to the next form. If it is a new record I want the form to load with a blank form but pulling across the ClientID (unique identifier) but if a record already exists then link by the ClientID. So if going from frmInitial to frmFamily some code that says if new record then ClientID in frmFamily will equal ClientID in frmInitial but if revisiting the record (i.e. data already input but being edited or viewed) the correct record as per ClientID appears.

    I already have the following in the Where Condition section of a macro [Forms]![frmInitial]![PatientID]=[tblFamily]![PatientID] and an OnLoad expression to carry over ClientID if a new record but this doesn't seem to work for the command button - any ideas??

    Help much appreciated
    Lucie
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    In The calling form

    Code:
    Private Sub Go2FormB_Click()
    If Not IsNull(Me.OrderID) Then
      DoCmd.OpenForm "TableB", , , , , , Me.OrderID
     Else
      MsgBox "A Visit ID Must Be Entered First!"
     End If
    End Sub
    In the called form

    Code:
    Private Sub Form_Load()
    
    If Not IsNull(Me.OpenArgs) Then
    
     Set rst = Me.RecordsetClone
     
     rst.FindFirst "[OrderID] = '" & Me.OpenArgs & "'"
    
      If Not rst.NoMatch Then
          Me.Bookmark = rst.Bookmark
       Else
        DoCmd.GoToRecord , , acNewRec
        Me.OrderID = Me.OpenArgs
       End If
    
    rst.Close
    Set rst = Nothing
    End If
    
    End Sub
    The above code assumes that OrderID is Text. If it is Numeric instead, replace

    rst.FindFirst "[OrderID] = '" & Me.OpenArgs & "'"

    with

    rst.FindFirst "[OrderID] = " & Me.OpenArgs


    Linq ;0)>

    Comment

    • luciegiles
      New Member
      • Oct 2007
      • 56

      #3
      Great, that works - for the second part I already had an OnLoad event to pull in a few other fields as follows:

      If Me.NewRecord Then
      Me.ClientID = [Forms]![frmClientDetail s].[ClientID]
      Me.CHI = [Forms]![frmClientDetail s].[CHI]
      Me.ClientForena me = [Forms]![frmClientDetail s].[ClientForename]
      Me.ClientSurnam e = [Forms]![frmClientDetail s].[ClientSurname]
      End If

      How can I incorporate that into the Load event you describe?

      Comment

      Working...