Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004
    Location
    Raleigh, NC
    Posts
    146

    Unanswered: Passing information between subforms

    I have a main form (frmMain) that contains two sub forms (subCustomers) and (subOperations). I have a textbox in (subOperations) called "txtAccountSearch" that I type an account number into and then I click a command button (cmdAccountGo) and it searchs for a specified Account Number. I want the result of the search to appear in the first subform (subCustomers) instead of in a new form. I was able to do this when I had 1 form with a tab control on it, but I've been unable to accomplish it with subforms. Any suggestions or a point in the right direction would be appreciated! Here's the code behind my command button:

    Private Sub cmdAccountGo_Click()
    On Error GoTo Err_cmdAccountGo_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmCustomers"

    stLinkCriteria = "[AccountNo] LIKE " & "'*" & [txtAccountSearch] & "*'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    With Me
    .OrderByOn = True
    .OrderBy = "AccountNo"
    End With

    Exit_cmdAccountGo_Click:
    Exit Sub

    Err_cmdAccountGo_Click:
    MsgBox Err.Description
    Resume Exit_cmdAccountGo_Click
    End Sub

  2. #2
    Join Date
    Mar 2004
    Location
    belgium
    Posts
    290
    a form.refresh may be ???????????

  3. #3
    Join Date
    Nov 2003
    Location
    LONDON
    Posts
    238
    There are a number of ways you can do this. The simplest method is to place the search text box and the command button on the main form, then use this code:

    Private Sub cmdAccountGo_Click()
    On Error GoTo Err_cmdAccountGo_Click

    Dim stLinkCriteria As String

    stLinkCriteria = "[AccountNo] LIKE " & "'*" & Me("txtAccountSearch").Value & "*'"

    Me("subCustomers").Form.RecordSource = "SELECT * FROM {Name of your query/table} WHERE (" & strLinkCriteria & ")"

    Exit_cmdAccountGo_Click:
    Exit Sub

    Err_cmdAccountGo_Click:
    MsgBox Err.Description
    Resume Exit_cmdAccountGo_Click
    End Sub

Posting Permissions

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