Results 1 to 5 of 5
  1. #1
    blueraincoat is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Shanghai,CHN
    Posts
    99

    Text Get Focus


    Hi All, I made a form based on a query.After the form is opened, if there's no data displayed in the form, I want a text get focus and let user enter the part number which they want to view. I wrote a little code, but it did not work. I don't know what's wrong about it. Could someone help?
    Failed to upload the db I attached a picture of the form in design mode.

    Private Sub Form_Activate()
    If IsNull(Me.txtPartNumber) Then
    Me.txtText15.SetFocus
    End If
    End Sub

  2. #2
    ansentry's Avatar
    ansentry is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2009
    Location
    Melbourne, Australia
    Posts
    67
    Have a look at my attached sample. You will see that I have put my code behind "OnCurrent".

    On my forms I put a command button, name it cmdDud and then make it transparent. I set focus to it when I don't want to display a cursor.

    In this case if the partnumber is "null" then the focus will go to it but if it is "NotNull" it will go to cmdDud and the user will not see it.

    Hope this helps...

  3. #3
    blueraincoat is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Shanghai,CHN
    Posts
    99
    Thank you for reply,ansentry.
    I found what's wrong.

    Private Sub Form_Activate()
    If IsNull(Me.txtPartNumber) Then
    Me.txtText15.SetFocus
    End If
    End Sub

    When the code is like above, it will give a error message saying "Method or data member not found". I didn't see this last night because i run it in my WIN7 laptop.
    This moring in the office, i changed it as below

    Private Sub Form_Activate()
    If IsNull(Me.PartNumber) Then
    Me.Text15.SetFocus
    End If
    End Sub

    Everything is OK now. Shouldn't it be Me.txtPartNumber? I got this idea when i read a book by Alison Balter.

  4. #4
    ansentry's Avatar
    ansentry is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2009
    Location
    Melbourne, Australia
    Posts
    67
    Your correct I missed the first Me.
    Code:
    If IsNull(Me.txtPartNumber) Then
        Me.txtPartNumber.SetFocus
    Else
        Me.cmdDud.SetFocus ' this is a tranparent command button on the form.
    End If
    
    End Sub
    Why do you use Private Sub Form_Activate() instead of Private Sub Form_Current()

  5. #5
    blueraincoat is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Shanghai,CHN
    Posts
    99
    the sequence of event when a form is open: open load resize activate current, so i put it in an activate event, but i think it would also be fine using the current event

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Grow text box on form with focus
    By Karen H in forum Forms
    Replies: 5
    Last Post: 02-25-2011, 12:03 PM
  2. Passing focus to subform.....
    By smorelandii in forum Forms
    Replies: 3
    Last Post: 02-04-2011, 10:51 AM
  3. Setting Focus on a Form
    By MFeightner in forum Forms
    Replies: 1
    Last Post: 07-30-2009, 07:49 AM
  4. Set focus to another program
    By DrewB in forum Programming
    Replies: 1
    Last Post: 06-24-2009, 06:38 AM
  5. Keeping focus
    By ronatnc in forum Forms
    Replies: 0
    Last Post: 12-16-2008, 12:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums