Results 1 to 4 of 4
  1. #1
    Mario_1955 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2020
    Posts
    1

    Question Set focus on form based on the form name in control box

    Hi, if someone can fix this code below please,
    I have the control Txt1 in form1 it has the name of an already opened form2
    I need to set the focus on form2 using the form2 name in control Txt1.
    I used open form method but it took me to new record while I need it (form2) to stay on the same record.
    Thanks.
    Private Sub TxT1_Click()


    Dim stFrm As String
    stFrm = TxT1 '(Control contains the form name)
    Forms.stFrm.SetFocus '(I'm having error here)
    End Sub

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Have you tried Forms(Me.TxT1).SetFocus (or Forms(stFrm).Setfocus)?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    Quote Originally Posted by Mario_1955 View Post
    Hi, if someone can fix this code below please,
    I have the control Txt1 in form1 it has the name of an already opened form2
    I need to set the focus on form2 using the form2 name in control Txt1.
    I used open form method but it took me to new record while I need it (form2) to stay on the same record.
    Thanks.
    Private Sub TxT1_Click()
    Dim stFrm As String
    stFrm = TxT1 '(Control contains the form name)
    Forms.stFrm.SetFocus '(I'm having error here)
    End Sub
    Try:
    Dim stFrm As String
    stFrm = Me.TxT1.Text
    Forms(stFrm).Form.SetFocus
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    umm,

    - txt1 contains the name of the form where the focus is to be set and it isn't where the focus is supposed to go?
    - you have to give a control the focus before you can get its Text property value
    - if a form has enabled controls, you cannot set focus to the form, only to an enabled control?
    - Forms(stFrm).Form.SetFocus: I'm not seeing that form2 is a subform, which is kinda what that looks like. Maybe I'm missing that or not understanding that line.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 7
    Last Post: 06-02-2020, 01:57 PM
  2. Replies: 2
    Last Post: 03-22-2019, 05:35 PM
  3. Replies: 7
    Last Post: 04-24-2015, 11:29 AM
  4. Replies: 5
    Last Post: 03-05-2015, 03:46 PM
  5. Replies: 9
    Last Post: 10-20-2014, 08:43 PM

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