0
votes

I'm new to this. I have created a navigation form with 3 tabs. when I click on one tab it opens a pop-up form where I chose a record from a drop-down. when I click on a command button to "open file" I want the form to open in the tabs 'sub-form window'. at the moment all it does is opens in a separate window.
how do I get the form to open in the navigation sub-form window where it is linked, with the correct information in the fields based on the combo box?

Private Sub Amend_record_Click()
On Error GoTo Err_Amend_record_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    vFormName = Screen.ActiveForm.Name
    stDocName = "invoice_amend"

    vtest = Me![Combo0]
    stLinkCriteria = "[InvoiceID]=" & Me![Combo0]


    DoCmd.OpenForm stDocName, acNormal, , , acFormEdit, , stLinkCriteria
    Forms![navigation_form]!NavigationButton18.SetFocus


    DoCmd.Close acForm, vFormName

Exit_Amend_record_Click:
    Exit Sub

Err_Amend_record_Click:
    MsgBox Err.Description
    Resume Exit_Amend_record_Click

End Sub
2
Mind sharing your code? This helps other users to answer your question in a more specific way.Daan
first opens in new window but cant get it to open in tab on main form. Dim stDocName As String Dim stLinkCriteria As String vFormName = Screen.ActiveForm.Name stDocName = "invoice_amend" vtest = Me![Combo0] stLinkCriteria = "[InvoiceID]=" & Me![Combo0] 'DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria, acFormEdit 'DoCmd.OpenForm Navigation_form!invoice_amand DoCmd.BrowseTo acBrowseToForm, "navigation_form", "invoice_amand.NavigationSubform>navigation_form.NavigationSubform" DoCmd.Close acForm, vFormNameMike
found new bit of code to .setfocus but the form still opens in separate window and not in the tab at the selected position (combo box selection).Mike
The line DoCmd.OpenForm stDocName... means that you're opening a new form. Instead you want to show this as a sub-form in the tab you started from, right? So you need a sub-form control in that tab, you set the Source Object of that sub-form control to the form which needs displaying, and put your filter on that.user3728595
Hi, OK so how do i do that? what do you mean by "sub-form control" so how does that look in VBA? will this then link the data called in the combo box to the open form? i.e, if the record selected in the pop-up form in the combo box is 36 then will record 36 be displayed in the form on the tab as a sub-form?Mike

2 Answers

0
votes

So you have a form called navigation_form which contains a navigation control. Get the name of that control by selecting it and looking at the properties - let's say the name is NavigationSubform (which I think is the default).

Instead of your line of code DoCmd.OpenForm stDocName... you need to use:

With Forms![navigation_form]![NavigationSubform]
    .SourceObject = stDocName
    .Form.Filter = stLinkCriteria
    .Form.FilterOn = True
End With

This will open the form you require, filtered to the record you require, but instead of showing it in a new window it is shown as a subform to your original form.

0
votes

This is a solution more simple (i think):

DoCmd.OpenForm "navigation_form"
Forms("navigation_form").NavigationControl0.Tabs(1).SetFocus
SendKeys " ", True

NavigationControl0 is block in the navigation_forms that contains the buttons. Tabs(1) is the second tab in the menu (you can change it). The last command SendKeys " ", True simulate the click for open the correct form.