Results 1 to 7 of 7

Thread: GoToRecord

  1. #1
    Join Date
    Oct 2003
    Posts
    81

    Exclamation Unanswered: GoToRecord

    I have a form with two subforms. On one subform I want to have an onClick event where it goes to a specific record based on the item clicked.

    Example:

    Click on service type 1 (within subform 1) the second subform should go to the record which matches the serviceID clicked on in subform1.

    I'm using the gotoRecord method and it works if I open the subform manually, but if I don't, it gives me an error and says, form not open.

    I've tried setfocus to try and get the other form to run the gotorecord method, but it's not working!

    Code:

    ' First, get the record ID of the file item that was clicked
    ' Set the record id into a variable
    RecordID = Me.ServiceID

    ' Move to the record with a matching ServiceID.
    Forms!frmjob!FrmService.SetFocus
    DoCmd.GoToRecord acActiveDataObject, "FrmService", acGoTo, RecordID



    What am I doing wrong??? Is there a better way to go about doing this?

  2. #2
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    I don't know if I am reading your posting correctly but is sounds like you want to click on a record in one subform and that results in finding a corresponding record in the second sub form.

    Why not make an OpenForm macro and place the macro on one of the fields of the first sub form and have that macro open the corresponding record in a form that is a copy of your second subform.

  3. #3
    Join Date
    Oct 2003
    Posts
    81

    Lightbulb Tried that

    Good idea, but I tried that already. It works as far as opening the second form and changing the result in that form, but then I have two windows open and one disappears behind the other and I have to reclick each time to open the form.

    There has to be a way to change the record in that second subform...

    Anyone???

  4. #4
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    You said There has to be a way to change the record in that second subform... I assume you do not mean change the data.

    Make the form that opens (as per our previous posting) a "pop up" and have the macro position it with MoveSize.

    Another way with a macro is to use FindRecord.

    Let's say in SubForm1 you have an ID number and of course a matching ID number in Subform2.

    On Subform 2 you place an unbound text box. When you click on a field in Subform1 a macro runs which for starters with Setvalue places the ID number in the Subform 2 unbound text box.

    The next part of the Macro is FindRecord on subform2 where the ID number matches the number in the unbound text box.

    My index system works this way although it does not involve subforms but I think it will still be fine as long as the reference to the subform is OK.

    This is part of what I have.

    Item [Forms]![MasterForm]![Text1397]
    Expression [Forms]![Query466]![NameNumber]

    Next part is SelectObject which is MasterForm

    Then

    Find Record action and first line is

    =[Forms]![MasterForm]![Text1397]
    Last edited by Mike375; 04-28-04 at 21:21. Reason: Typos

  5. #5
    Join Date
    Oct 2003
    Posts
    81
    Tried the popup. Too much fuss with getting the window alignment to match perfectly.

    Can you explain the find record method a little better, I don't understand.

    Thanks.

  6. #6
    Join Date
    Apr 2004
    Location
    Sydney Australia
    Posts
    369
    Firstly, I use Access 95 and if you are using a much later version some of the macro actions maybe different names.

    The FindRecord action is essentially using the "binoculars" via a macro action.

    =[Forms]![MasterForm]![Text1397] (you will need to add the subform name as well for the correct reference) is placed in the FindRecord will find a record which has in the selected field a value the same as Text1397.

    The matching record you want to find in Subform 2 should have some for ID that matches the record in Subform 1. I use a field which I call NameNumber and I will use that here as it is in mind!!

    So let's say the record in Subform 1 has a NameNumber value of 12345. Thus you want to find the record in Subform 2 that also has the NameNumber value of 12345.

    To Subform 2 you add an unbound text box, which in my case is called Text1397.

    The first part of the macro action uses SetValue to set the value of text1397 on Subform 2 to be equal to the value of the NameNumber field on the selected record on Subform 1.

    The next macro action is to SelectObject and that is your Subform 2. The next macro action is GoToControl and for me that would be NameNumber.

    Then comes FindRecord which for me will be

    =[Forms]![MasterForm]![Text1397]

    Thus it finds the record in my Masterform where the NameNumber is the same value as Text1397.

    If it helps I can print out the macro actions from the macro and scan them and email you the PDF file

    Mike
    Last edited by Mike375; 04-29-04 at 10:09.

  7. #7
    Join Date
    Oct 2003
    Posts
    81
    Thanks for the help Mike. However I got it working a different way. I used a gotocontrol method which made the focus of the second subform and then ran the gotorecord method. All works perfectly!

Posting Permissions

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