Opening a Form based on a cmboBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chingchanglang
    New Member
    • Jun 2006
    • 6

    Opening a Form based on a cmboBox

    Hi, what I'm trying to do is probably very simple...but simple is relative! :D
    I have a cmbo box on a form "[View All Topics]". It is populated with a query to show me all the Topics in my table where the primary key is "Topic_Numb er". I want to choose one, select "Search" btn, and then have the "Topic_Informat ion" page display with it's results based on the Topic_Number. This is what I have in the "Search" button OnClick event. When it runs, the error is that it can not find the [Topic Information] form. It is not open yet, I know that is why. How can I open it (without it popping up) so that this code will find it? And is this code enough?


    Private Sub btn_SearchTopic _Click()
    On Error GoTo Err_btn_SearchT opic_Click
    Dim Criteria As String
    Dim MyRS As DAO.Recordset

    ' Find the record that matches the control
    'load form2 to use its recordset, but don't show it
    DoCmd.OpenTable ("[Topic Information]")


    Set MyRS = Forms![Topic Information].RecordsetClone
    Criteria = "Topic_Numb er= '" & Me!cmbo_topicnu mber & "'"
    MyRS.FindFirst Criteria

    If Not MyRS.NoMatch Then
    Forms![Topic Information].Bookmark = MyRS.Bookmark
    End If

    DoCmd.Close acForm, "[View All Topics]"

    'show form 1 with the bookmarked record?
    DoCmd.OpenForm [Topic Information]

    Exit_btn_Search Topic_Click:
    Exit Sub

    Err_btn_SearchT opic_Click:
    MsgBox Err.Description
    Resume Exit_btn_Search Topic_Click

    End Sub
    Last edited by chingchanglang; Jun 5 '06, 03:33 PM. Reason: updates
  • wlc04
    New Member
    • May 2006
    • 70

    #2
    Private Sub btn_SearchTopic _Click()
    On Error GoTo Err_btn_SearchT opic_Click
    Dim Criteria As String
    Dim MyRS As DAO.Recordset

    ' Find the record that matches the control
    'load form2 to use its recordset, but don't show it
    'DoCmd.OpenTabl e ("[Topic Information]")
    DoCmd.OpenForm "Topic Information"
    Forms![View All Topics].SetFocus
    Forms![Topic Information].Visible = False


    Set MyRS = Forms![Topic Information].RecordsetClone
    Criteria = "Topic_Numb er= '" & Me!cmbo_topicnu mber & "'"
    MyRS.FindFirst Criteria

    If Not MyRS.NoMatch Then
    Forms![Topic Information].Bookmark = MyRS.Bookmark
    End If

    DoCmd.Close acForm, "[View All Topics]"

    'show form 1 with the bookmarked record?
    DoCmd.OpenForm [Topic Information]

    Exit_btn_Search Topic_Click:
    Exit Sub

    Err_btn_SearchT opic_Click:
    MsgBox Err.Description
    Resume Exit_btn_Search Topic_Click

    End Sub

    Comment

    Working...