Results 1 to 6 of 6
  1. #1
    HelpDesk is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jun 2015
    Posts
    42

    Question Text box Manipulation

    So I am trying to do a few things to a text box and I can't quite get it to do what I want.

    I want it to:



    1. Check to see if the what the user input into the text box is a record. (It does this currently)

    2. If the user types in something that is not a record and moves from the textbox a popup comes up and the user has to type in a valid string.

    This is the code:

    Code:
    Private Sub Upstream_AfterUpdate()
        Dim rst As DAO.Recordset
        
        Set rst = CurrentDb.OpenRecordset("Devices", dbOpenDynaset)
        
        'Check to make sure Upstream Device is in Devices Table
        With rst
            .FindFirst ("[Device ID]='" & Upstream.Text & "'")
            If .NoMatch And Len(Upstream.Text) > 0 Then
                MsgBox "Not a valid Upstream Device"
                
                'Set cursor back to Upstream textbox
                Me.Upstream.SetFocus
                Me.Upstream.SelStart = Nz(Len(Me.Upstream), 0)
                
            Else
            'Do Nothing
            End If
        End With
    End Sub
    It correctly searches the proper column for the record and displays a pop up when it is incorrect but it does not keep the cursor in the textbox until the user inputs a valid string.

    Any ideas as to why this code isn't working?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You can try setting focus somewhere else and then where you want it. You can use the before update event and set

    Cancel = True
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    HelpDesk is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jun 2015
    Posts
    42
    Quote Originally Posted by pbaldy View Post
    You can try setting focus somewhere else and then where you want it. You can use the before update event and set

    Cancel = True
    There are more than one textbox in the form so I don't want that to be the first one that focus is brought to when the form opens.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I mean in the same code:

    Me.SomeplaceElse.SetFocus
    Me.Upstream.SetFocus
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    HelpDesk is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jun 2015
    Posts
    42
    Quote Originally Posted by pbaldy View Post
    I mean in the same code:

    Me.SomeplaceElse.SetFocus
    Me.Upstream.SetFocus
    It worked! What a simple little fix haha
    Thank You!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Data Manipulation
    By Thompyt in forum Programming
    Replies: 7
    Last Post: 03-27-2015, 05:32 PM
  2. String text manipulation
    By justphilip2003 in forum Access
    Replies: 2
    Last Post: 03-21-2013, 09:56 PM
  3. date manipulation
    By lpsd in forum Access
    Replies: 3
    Last Post: 12-23-2010, 12:06 PM
  4. Form Manipulation examples
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-24-2010, 12:03 AM
  5. Query manipulation using VBA
    By benattal in forum Programming
    Replies: 0
    Last Post: 12-31-2008, 09:12 AM

Tags for this Thread

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