TabStop not working (1 Viewer)

John Sh

Member
Local time
Tomorrow, 04:56
Joined
Feb 8, 2021
Messages
408
I am trying to set the TabStop property in vba.
I have a textbox named "txtControl".
So, me.txtcontrol.TabStop = true morphs into me.txtControl.tabstop = True
I would expect me.txtControl.TabStop = True
Running the code does not create an error, nor does it affect the TabStop property of the control.
This indicates that vba is not recognising TabStop as a genuine property of a text box although it appears in the dropdown as "TabStop" after "me.txtControl."
How do I programmatically control the user's ability to tab into a control?
I can easily lock the control to stop changes but I need certain controls to be skipped over under certain circumstances.
Changing the TabStop property seems to be the logical way to do this.
Am I missing something in the "File - Options" window or the "Form.Load" event?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:56
Joined
Oct 29, 2018
Messages
21,453
Which event are you using to run this code?
 

John Sh

Member
Local time
Tomorrow, 04:56
Joined
Feb 8, 2021
Messages
408
Which event are you using to run this code?
I have three levels of user, "intLevel"
Level 1 is a supervisor and has full rights.
Level 2 is an operator and can create new records and alter some data.
Level 3 is a student and can only view the data.
Once a new record has been saved, then critical data can only be modified by a supervisor.
Other users can view this data but it is skipped over in the tab order.
The following code is called to set the access to these controls depending on who is logged in and what they are doing.
A level 3 operator cannot create a new record so never gets to call this code.

Code:
Public Function setLocked(ByVal frm As Form, str As String)
    Dim isLocked As Boolean
    Dim isLimit As Boolean
    Dim istab As Boolean
    isLocked = True
    isLimit = True
    istab = False
    If intLevel = 1 Then
        isLimit = False
        istab = True
    End If
    If intLevel = 1 Or frm.NewRecord Then
        isLocked = False
        istab = True
    End If
    frm.[TxtCreateD].Locked = True
    frm.[TxtCreatedby].Locked = True
    frm.[TxtHerbarium].Locked = True
    frm.[TxtCreateInst].Locked = True
    frm.[txtAccNo].Locked = isLocked
    frm.[cboFamily].Locked = isLocked
    frm.[cboGenus].Locked = isLocked
    frm.[cboEpithet].Locked = isLocked
    frm.[txtAccNo].tabstop = istab
    frm.[cboFamily].tabstop = istab
    frm.[cboGenus].tabstop = istab
    frm.[cboEpithet].tabstop = istab
    If InStr(str, "C") = 0 Then
        frm.[cboSupra].Locked = isLocked
        frm.[txtBoxNo].Locked = isLocked
        frm.[cboEpithet].Locked = isLocked
        frm.[cboSupra].tabstop = istab
        frm.[txtBoxNo].tabstop = istab
        frm.[cboEpithet].tabstop = istab
        frm.[cboSupra].LimitToList = isLimit
        frm.[cboGenus].LimitToList = isLimit
        frm.[cboFamily].LimitToList = isLimit
        frm.[cboEpithet].LimitToList = isLimit
    End If
End Function[
/CODE]

Locking the controls and limiting the combo boxes is not a problem, it is just setting the tabstop.
You will notice in the code that "tabstop" is in lower case whereas "Locked" and "LimitToList" are capitalised as expected.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:56
Joined
Oct 29, 2018
Messages
21,453
Other users can view this data but it is skipped over in the tab order.
Sorry, that didn't answer which event you're using. Also, what if the unauthorized user uses the mouse to click into the control they're supposed to skip? How are you preventing that?
 

John Sh

Member
Local time
Tomorrow, 04:56
Joined
Feb 8, 2021
Messages
408
A supplementary question.
Should I be aable to setfocus to a control that has the tabstop set to "No"?
 

John Sh

Member
Local time
Tomorrow, 04:56
Joined
Feb 8, 2021
Messages
408
Sorry, that didn't answer which event you're using. Also, what if the unauthorized user uses the mouse to click into the control they're supposed to skip? How are you preventing that?
I'm not using an event to call the code.
It is run in Form_Current to lock these controls then after a "New" button is clicked to create a new record.
Even if a user does click on a locked control, which is most unlikely, there is no way for them to alter data since the control is locked.
I could disable the control but that creates a readability problem that would defeat the purpose.
This code presets some controls in the new record and the call to "isLocked" sets the level of access to the others.
Some of the controls that are set before the call to islocked may well be changed as data is entered, these controls are open to access by level 1 or 2 operators

Code:
Private Sub NewBtn_click()
    Dim str As String
    If intLevel = 3 Then
        MsgBox "Students are not authorised to create new records!"
        Exit Sub
    End If
    DoCmd.GoToRecord Record:=acNewRec
    Me.lblOrder.Caption = "Order"
    Me.txtAccNo = DMax("AccessionNumber", "main") + 1
    Me.TxtCreateD = Date
    Me.TxtHerbarium = "The Don McNair Herbarium"
    Me.cboInAus = "Aust"
    Me.TxtLatDir = "S"
    Me.TxtLongDir = "E"
    Me.cboBot = "Aust"
    Me.cboKOC = "Sheet"
    Me.txtConStat = "S"
    Me.txtStatus = "A"
    Me.txtAccStat = "C"
    Me.txtNameS = "A"
    Me.cboDet = "D"
    Me.Label = True
    Me.Label.BackColor = RGB(218, 255, 94)
    Me.TxtCreateInst = "University of Newcastle"
    Me.TxtCreatedby = strFullName
    Call setLocked([Forms]![main collection], "Z")
    Me.txtAccNo.SetFocus
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:56
Joined
Oct 29, 2018
Messages
21,453
A supplementary question.
Should I be aable to setfocus to a control that has the tabstop set to "No"?
Yes, you should. TabStop only affects the Tab key.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:56
Joined
Oct 29, 2018
Messages
21,453
You will notice in the code that "tabstop" is in lower case whereas "Locked" and "LimitToList" are capitalised as expected.
That can be explained. However, when you say the tab stop is not being affected makes no sense. I just gave it a try, and it worked for me. You might consider posting a sample copy of your db for analysis.

Just a thought...
 

John Sh

Member
Local time
Tomorrow, 04:56
Joined
Feb 8, 2021
Messages
408
That can be explained. However, when you say the tab stop is not being affected makes no sense. I just gave it a try, and it worked for me. You might consider posting a sample copy of your db for analysis.

Just a thought...
I'm going to mull this over for a while. I am getting some quite bizarre behaviour at the moment. What was working is now not and what wasn't is.
I'm going to shut this down for a while and come back to it later, hopefully with a clear head.
I thank you for your time so far.
John
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:56
Joined
Oct 29, 2018
Messages
21,453
I'm going to mull this over for a while. I am getting some quite bizarre behaviour at the moment. What was working is now not and what wasn't is.
I'm going to shut this down for a while and come back to it later, hopefully with a clear head.
I thank you for your time so far.
John
Good luck!
 

Users who are viewing this thread

Top Bottom