Results 1 to 3 of 3
  1. #1

    SetFocus to subform control (2000, SR1)

    The code that follows works perfectly for what it needs to do, except that when I want it to set the focus on a subform control (line in red), it ignores it and the focus stays on the command button which activates the code. The command button is on the main form, the control I want it to move to on opening, is on the subform.

    I have done this with a control on the same form (ControlName.SetFocus) and never had any problem. I think I am referencing it correctly (I have tried it with brackets and without, no difference), but I cannot think of any other reason I cannot move the focus. Is there something needed to remove the focus from the command button, or do I need code to focus to the subform control?

    Main form name = frmL60Clean
    Subform control name = sfCL60 (Subform is named "sbfrmClean60", but I believe it is the control name that needs to be referenced? VBE didn't like it when I tried using the subform name -- said it couldn't find that field name)
    Control I want it to open to = txtOp

    Everything else does fine -- all it is doing is asking for criteria, passing them to variables, confirming the entry, finding the record, and if not, returns a message that it doesn't exist.

    All the reading and help files indicate that I have referenced it correctly; something else has to be missing. Appreciate any feedback as to what it may be.


    <font color=blue>
    Private Sub cmdGet60c_Click()

    On Error GoTo Err_cmdGet60c_Click

    Dim rst As DAO.Recordset
    Dim strSearch As String, strSN As String, strEnd As String, strPc As String
    Dim strMsg As String, strConfirm As String

    Set rst = Me.RecordsetClone

    <font color=448800>'get user input of billet and part number to open record</font color=448800>
    strSN = Trim(InputBox("Enter Billet ID - 5 digit NUMBER only, no B", "Serial Number"))
    strEnd = Trim(InputBox("Enter End ID", "Which End -- A or B?"))
    strPc = Trim(InputBox("Enter Piece #", "Piece Number"))

    <font color=448800>'store input to variables</font color=448800>
    strSearch = "[Bill_Num] = '" & strSN & "' AND "
    strSearch = strSearch & "[Bill_Half] = '" & strEnd & "' AND "
    strSearch = strSearch & "[PcNum] = '" & strPc & "'"

    <font color=448800>'Feed back message box to confirm entry</font color=448800>
    strConfirm = "BILLET: " & strSN & "" & vbCrLf _
    & "END: " & strEnd & "" & vbCrLf _
    & "PIECE: " & strPc & "" & vbCrLf & vbCrLf _
    & "If Correct, press OK, BUT ..." & vbCrLf & vbCrLf _
    & "-- If INCORRECT --" & vbCrLf _
    & " Cancel and retry." & vbCrLf & " "

    If MsgBox(strConfirm, 289, "PLEASE CONFIRM REQUEST") = vbOK Then

    <font color=448800>'find the record</font color=448800>
    rst.FindFirst strSearch
    <font color=red>Forms!frmL60Clean!sfCL60!txtOp.SetFocus</font color=red>
    End If<font color=448800> 'end if of confirmation message box

    'continue with code to find record and
    'report if it is valid or not</font color=448800>
    If Not rst.NoMatch Then
    Me.Bookmark = rst.Bookmark

    <font color=448800>' Give message that record not found, try again or contact QA</font color=448800>
    strMsg = "Please check the Billet ID, END and" & Chr(13)
    strMsg = strMsg & "Piece Number and Try Again." & vbCrLf & vbCrLf _
    & "If Repeat Effort Fails," & Chr(13) _
    & "Contact Supervisor. Thank You."

    MsgBox strMsg, 16, "!!NO SUCH RECORD EXISTS!!"

    End If

    Set rst = Nothing

    Exit Sub

    MsgBox Err.Description
    Resume Exit_cmdGet60c_Click

    End Sub
    </font color=blue>

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Crystal Beach, FL, Florida, USA
    Thanked 33 Times in 33 Posts

    Re: SetFocus to subform control (2000, SR1)

    You need to do 2 things: set the focus to the subform, then set the focus to the control you want.

    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3

    Re: SetFocus to subform control (2000, SR1)

    Thanks Mark. Worked perfectly

    I never thought about setting focus to the sf control first.

    Curious -- Was the extra form! after the sf control name in line 2, necessary because I chose to name the control? I don't seem to recall needing it when doing "Forms!frmParent!sbform!" type reference. Or is it needed when setting focus from the main form, as in this case?

    Also, why did it not generate an error? It just gave me the silent treatment.


Posting Permissions

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