Focus doesn't Move to Main Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • massamiya
    New Member
    • Aug 2010
    • 8

    #1

    Focus doesn't Move to Main Form

    Please help me.
    I have hit a brickwall and can't figure out what the problem is
    I have a main form call (Prods)and subform called Prodsub and both are unbound. I call the Mainform from a "start menu form" with the Docmd.OpenForm "prods" the mainform has a START and END date text box that the user has to input the date to filter data from a db with a query in the VB Code (not embedded in the form) and 3 Cmd buttons "Update, Print and End"
    When the form loads focus doesn't move to the Date text box for
    the START and END dates to be entered instead the VB codes runs without any dates and as a consequence no filtering occurs and no data is selected and after this the START Date txtbox gets focus.
    I am using the subform to display tabular data retrieved from several tables.
    How do I get the Main form to load and set focus to the Start
    TxtBox immediately ?
    Attached Files
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    In "Private Sub Form_Load()" enter =
    Code:
    Private Sub Form_Load()
       Show
       Text1.SetFocus
    End Sub
    see Help VB6:

    The object must be a Form object, MDIForm object, or control that can receive the focus. After invoking the SetFocus method, any user input is directed to the specified form or control.

    You can only move the focus to a visible form or control. Because a form and controls on a form aren't visible until the form's Load event has finished, you can't use the SetFocus method to move the focus to the form being loaded in its own Load event unless you first use the Show method to show the form before the Form_Load event procedure is finished.

    You also can't move the focus to a form or control if the Enabled property is set to False. If the Enabled property has been set to False atdesign time, you must first set it to True before it can receive the focus using the SetFocus method.

    Comment

    • massamiya
      New Member
      • Aug 2010
      • 8

      #3
      ggeu;
      Thanks very much for the prompt response to my
      query. I am a newbie as regards programming in VBA.
      I will try to edit my program and see whether it will
      work based on my understanding of what you wrote.
      Did you have a glance at my enclosed code to see what
      I am doing wrong ?

      Comment

      • Guido Geurs
        Recognized Expert Contributor
        • Oct 2009
        • 767

        #4
        Yes, I have seen Your code, but it's easier for me if You can attach Your VB program files in BYTES so I don't have to rebuild it and maybe make mistakes in the elements and names with the result that we are talking on different bases!
        In Your TXT file there are also some strange characters!
        So I don't trust it for 100% : are there codes, lines, missing... ?!

        Comment

        • massamiya
          New Member
          • Aug 2010
          • 8

          #5
          Thanks indeed.
          I am afraid I don't understand what you mean by
          me sending my VB programs In BYTES.
          The Show method you indicated earlier fails at compile.
          I have a question,
          Does "Show" and Forms![MyFORM].Visible = True both
          achieve the same result of making a form visible ?
          I didn't enclose the entire program just code on loading of
          the form and filtering condition where I am encountering
          the problem of not being able to set focus on the StartDate textBox
          immediately after the main and Subform are loaded.
          Is the problem I am encountering due to my main and subform being
          both unbounded ?
          Maybe the strange letters you see are due to my keyboard being a
          Japanese keyboard.

          Comment

          • massamiya
            New Member
            • Aug 2010
            • 8

            #6
            [
            Private Sub Form_Load()
            Me.Caption = "【 Product Inventory List 】"
            End Sub

            Private Sub Form_Activate()
            On Error Resume Next
            DoCmd.Maximize
            ClrScr
              Me.Requery
            Call UpDate_Click
            End Sub

            Public Sub ClrScr()
            On Error GoTo Err_ClrScr
            Me.Painting = False: DoCmd.Hourglass True: DoCmd.SetWarnin gs False
            Me.Requery
            End_ClrScr:
            DoCmd.SetWarnin gs True: DoCmd.Hourglass False: Me.Painting = True
            Exit Sub
            Err_ClrScr:
            MsgBox Err.Description
            Resume End_ClrScr
            End Sub

            Private Sub StartDate_After Update()
            Call DatFilter
            End Sub

            Private Sub StartDate_Befor eUpdate(Cancel As Integer)
            Call DatFilter
            End Sub

            Private Sub StartDate_Exit( Cancel As Integer)
            Call DatFilter
            End Sub

            Private Sub EndDate_AfterUp date()
            Call DatFilter
            End Sub

            Private Sub EndDate_BeforeU pdate(Cancel As Integer)
            Call DatFilter
            End Sub

            Private Sub DatFilter()
            If IsNull(Me!Start Date) Or Me!StartDate = 0 Then
            Beep
            MsgBox "Pls Enter a Start date.", vbExclamation, "EntryError "
            StartDate.SetFo cus
            Exit Sub
            End If
            If IsNull(Me!EndDa te) Or Me!EndDate = 0 Then
            Beep
            MsgBox "Pls enter an ending date.", vbExclamation, "Entry Error"
            EndDate.Requery
            Exit Sub
            End If
            If IsNull(Me!EndDa te) Then
            Me!EndDate = Me!StartDate
            Me!EndDate.Requ ery
            End If
            If Me!EndDate = 0 Then
            Me!EndDate = Me!FromDate
            Me!EndDate.Requ ery
            End If
            stq = "DateProduc ed Between #" & StartDate & "# And #" & EndDate & "#"
            End Sub

            Private Sub EndDate_Exit(Ca ncel As Integer)
            Call DatFilter
            End Sub
            Private Sub UpDate_Click()
            Updating Code here
            End Sub
            ]

            Comment

            • massamiya
              New Member
              • Aug 2010
              • 8

              #7
              Try to post my code in BYTES but can't
              figure out how it is done.
              Can someone give me an insight.
              Thanks.

              Comment

              • Guido Geurs
                Recognized Expert Contributor
                • Oct 2009
                • 767

                #8
                Hox to post Your code:
                Place Your VB files (.VBP, .FRM,...) in a ZIP file.
                BYTES let only GIF, BMP, ..., ZIP files to be attached ( see list in the "Manage Attachments " window)

                Comment

                Working...