locked
Double_Click Help RRS feed

  • Question

  • Hello - SO I am having some trouble with the below code. The below code (Double_Click) is supposed to go to a specific record when clicked.

    The form where the Double_Click procedure is contained is a sub-form of sort [Service_Details_Subform]. The same form is also contained, as and actual sub-form [Service_Details_Subform_Main] within a main form [Service_Logging]. The double-click procedure comes into play when the sub-form [Service_Details_Subform] is opened in Datasheet view. When a record is double-clicked, it is supposed to reflect that record on the sub-form [Service_Details_Subform_Main] contained within the main form [Service_Logging].

    Here is the code I am using. The bolded is the part having difficulties with:

    Option Compare Database
    Option Explicit
     
    Private Sub Form_DblClick(Cancel As Integer)
    On Error GoTo Form_DblClick_Err
        
        DoCmd.SelectObject acForm, "Service_Logging" 'sets focus back to main form - works
        DoCmd.GoToControl "SvcDataID" 'located in subform "Service_Details_Subform_Main"....works
       DoCmd.GoToRecord , , [Forms]![Service_Logging]![Service_Details_Subform_Main]![SvcDataID] = [Forms]![Service_Details_Subform]![SvcDataID]
        DoCmd.GoToControl "SvcDate" 'located in subform "Service_Details_Subform_Main"....works
        DoCmd.Close ObjectType:=acForm, ObjectName:=Me.Name, Save:=acSaveNo 'works
            
    Form_DblClick_Exit:
        Exit Sub

    Form_DblClick_Err:
        MsgBox Error$
        Resume Form_DblClick_Exit
        
    End Sub

    The above code produces the following error:

    Below is a screenshot of the form(s) that may be helpful:
    If anyone can see what I may be doing wrong in the GoToRecord area, please let me know. This is becoming most frustrating :(  Maybe there is a better way of doing this? Any ideas will also be much appreciated. Been a while since I have dabbled in Access.

    Thank you in advance for your time and any assistance you may be bale to provide.

    Thank you

    Monday, March 18, 2019 6:34 PM

Answers

  • Ok I got it! Finally figured out something that works perfectly for what I was attempting to accomplish.

    Here is my end result:

    Private Sub Form_DblClick(Cancel As Integer)
    On Error GoTo Form_DblClick_Err

        With Forms!Service_Logging!Service_Details_Subform_Main.Form.RecordsetClone
           .FindFirst "SvcDataID=" & Me.SvcDataID
           
           If .NoMatch Then
              Beep
              Exit Sub
           End If
           
           Forms!Service_Logging!Service_Details_Subform_Main.Form.Bookmark = .Bookmark
        End With
        
        DoCmd.Close ObjectType:=acForm, ObjectName:=Me.Name, Save:=acSaveNo 'closed search form - works
        Forms!Service_Logging!Service_Details_Subform_Main.SetFocus
        
                
    Form_DblClick_Exit:
        Exit Sub

    Form_DblClick_Err:
        MsgBox Error$
        Resume Form_DblClick_Exit
        
    End Sub

    Thanks to everyone for your input. Assistance from these forums is always much appreciated.

    Thank you

    • Marked as answer by rstreets2 Tuesday, March 26, 2019 7:56 PM
    Tuesday, March 26, 2019 7:56 PM

All replies

  • If anyone can see what I may be doing wrong in the GoToRecord area, please let me know.

    Hi rstreets2,

    Does it help if you first set the focus to the subform, before going to the desired record on that subform?

    Imb.

    Monday, March 18, 2019 6:59 PM
  • Hi lmb and thank you for your quick response. So that is one method I have tried, but can't seem to actually set the focus to the subform in general. I can go to specific controls within the subform, but can get the focus direct to the subform [Service_Details_Logging_Main] itself; only the actual main form, [Service_logging].
    Monday, March 18, 2019 7:27 PM
  • only the actual main form, [Service_logging].

    Hi rstreet2,

    And when you use:

            [Forms]![Service_Logging]![Service_Details_Subform_Main].Form.SetFocus

    or (I believe this also works)

            [Forms]![Service_Logging]![Service_Details_Subform_Main].SetFocus

    Imb.

    Monday, March 18, 2019 7:36 PM
  • Hi lmb -

    So yes, the bottom method you provided actually errors out with the below....

    The top one produces no errors, but still unable to go to the desired record; same error message provided earlier.

    Here is where I put the setfocus line...

    DoCmd.SelectObject acForm, "Service_Logging" 'sets focus back to main form - works

    [Forms]![Service_Logging]![Service_Details_Subform_Main].SetFocus

    DoCmd.GoToControl "SvcDataID" 'located in subform "Service_Details_Subform_Main"....works DoCmd.GoToRecord , , [Forms]![Service_Logging]![Service_Details_Subform_Main]![SvcDataID] = [Forms]    [Service_Details_Subform]![SvcDataID]
    'DoCmd.GoToControl "SvcDate" 'located in subform "Service_Details_Subform_Main"....works

    DoCmd.Close ObjectType:=acForm, ObjectName:=Me.Name, Save:=acSaveNo 'works

    Monday, March 18, 2019 8:01 PM
  • Open the main form Service_Logging in design view.

    Click once on the subform to select it (don't click on it again, for that would select something in the subform).

    Look at the Name property in the Other tab of the Property Sheet. This is the name you should use in

    [Forms]![Service_Logging]![Service_Details_Subform_Main].SetFocus


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Monday, March 18, 2019 9:37 PM
  • Hi Hans!

    Thank you for your response. Yes, this is the same name I am using?

    Monday, March 18, 2019 10:03 PM
  • Could it be that I am using the same form as the sub-form and the datasheet view pop-up/search form?

    Although the subform contained in the main form is named [Service_Details_Subform_Main] on the main form, the actual form it is coming from is called [Service_Details_Subform]; which is also the same form called upon from the "Archives" button shown in pic in original post. The "Archives" button opens the same form, [Service_Details_Subform], in Datasheet view (pop-up window).



    • Edited by rstreets2 Monday, March 18, 2019 10:10 PM added (pop-up window)
    Monday, March 18, 2019 10:08 PM
  • Another tid-bit o info...

    When I use the GoToRecord in this manner, the double-click doe not error, but rather each time a record is double-clicked, it cycles through the next record until the end of records and then creates a new record....

    Using this (removing the italic below):     

    DoCmd.GoToRecord , , [SvcDataID] = [Forms]![Service_Details_Subform]![SvcDataID]

    Rather than this:   

    DoCmd.GoToRecord , , [Forms]![Service_Logging]![Service_Details_Subform_Main]![SvcDataID] = [Forms]![Service_Details_Subform]![SvcDataID]

    Monday, March 18, 2019 10:29 PM
  • Ok I got it! Finally figured out something that works perfectly for what I was attempting to accomplish.

    Here is my end result:

    Private Sub Form_DblClick(Cancel As Integer)
    On Error GoTo Form_DblClick_Err

        With Forms!Service_Logging!Service_Details_Subform_Main.Form.RecordsetClone
           .FindFirst "SvcDataID=" & Me.SvcDataID
           
           If .NoMatch Then
              Beep
              Exit Sub
           End If
           
           Forms!Service_Logging!Service_Details_Subform_Main.Form.Bookmark = .Bookmark
        End With
        
        DoCmd.Close ObjectType:=acForm, ObjectName:=Me.Name, Save:=acSaveNo 'closed search form - works
        Forms!Service_Logging!Service_Details_Subform_Main.SetFocus
        
                
    Form_DblClick_Exit:
        Exit Sub

    Form_DblClick_Err:
        MsgBox Error$
        Resume Form_DblClick_Exit
        
    End Sub

    Thanks to everyone for your input. Assistance from these forums is always much appreciated.

    Thank you

    • Marked as answer by rstreets2 Tuesday, March 26, 2019 7:56 PM
    Tuesday, March 26, 2019 7:56 PM