Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2004
    Posts
    100

    Unanswered: jump to selected record

    Hello,

    suppose I have:
    one form displaying all attributes of one table.
    On the form is a combobox displaying the primary key of all records.

    How can I based on a selection in the combobox jump to the selected record. I mean the record shall then be displayed in the form.

    How can I accomplish that?
    Thanks in advance!
    Regards, Proximus

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Your combobox now displays all the PrimKey values. Set the RowSource so as to add another non visible column to your ComboBox which will hold the actual record number related to the PimKey value and set properties to [ColumnCount = 2; ColumnWidths = 1";0"; BoundColumn = 1].

    Now in the OnClick event of your ComboBox, place the following code into a code window via the VBEditor.

    Code:
    DoCmd.GoToRecord acDataForm, "myFormName", acGoTo, _
    CLng(Me.myComboBoxName.Column(1))
    That should do the trick.


  3. #3
    Join Date
    Apr 2004
    Posts
    100
    I am not quite sure what you mean by
    "add another non visible column to your ComboBox which will hold the actual record number related to the PimKey value"
    how can i find out the actual record number?
    Regards Proximus

  4. #4
    Join Date
    Apr 2004
    Posts
    100
    hmm. It works now, however only if the records are in ascending order. I mean if the MS Access record number is different from the primary key autonumber it simply jumps to the record number. But I want it to jump to the primary key that I provide. Is there any way to do that?

    Another problem is the following. I've provided a screenshot of the error:
    The "resource_line subform" is a subform of the "request" form sitting in Request.
    So when running the docmd.gotorecord statement i get the error that the resource_line subform is not open.
    What can I do?
    Attached Thumbnails Attached Thumbnails untitled.jpg  
    Last edited by Proximus; 07-01-04 at 12:00.

  5. #5
    Join Date
    Apr 2004
    Posts
    100
    is there noone who could help me? please help !

  6. #6
    Join Date
    Nov 2003
    Posts
    1,487
    Hmmm...It's a subform you want to show the record(s) in... try this..

    Code:
    Private Sub cmbShowAllResourceLines_Click()
    Forms![Resource_Line Subform].RecordSource = "SELECT * FROM myTableName WHERE myTableName.myTableFieldNameWithPrimKey = '" & Me.cmbShowAllResourceLines & "';"
    Forms![Resource_Line Subform].Requery
    End Sub

  7. #7
    Join Date
    Apr 2004
    Posts
    100
    Hey. Thanks for your help!!
    When I use your code in main forms it works fine. However in the subforms i get the following error (see the picture).

    I have the forms Resource_Line sitting in Resource sitting in Request.

    Any ideas how to solve that error?
    Attached Thumbnails Attached Thumbnails untitled.jpg  

  8. #8
    Join Date
    Nov 2003
    Posts
    1,487
    It seems as though you are trying to set the RecordSource for the RESOURCE Subform control located within the Request Form. The subform control itself does not contain the RecordSource property thus issuing this very error.

    You need to set the RecordSource for the actual SubForm itself (located in the Forms section of your databsae window). It to appears to be named RESOURCE Subform.

    Try this:

    Code:
    Dim strQuery As String
    StrQuery = "SELECT * FROM Resource WHERE Resource.Res_id = " _
    Me.cmbShowAllResources.Coumn(0) & ";"
    Forms![RESOURCE Subform].RecordSource = strQuery
    Forms![RESOURCE Subform].Requery
    Give that a shot....


Posting Permissions

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