Setting a property on page within a tab control (1 Viewer)

NigelFletcher

New member
Local time
Today, 09:21
Joined
Mar 7, 2019
Messages
5
Sometimes I think my brain just ceases up on me and logic goes out the windows. I wonder if anyone can help me.

I have a form called welcome with has a tabcontrol on it called TabCtl0
On that control I have a page(tab) called Hard-Disks
When clicking on the tabs page "Hard Disks" the form is set to already set to Allowedits = False


I have a button that toggles be allowedits = False and Allowedits = true

Private Sub Command29_Click()
If Command29.Caption = "Locked" Then
Command29.Caption = "Edit"
Me.[Hard-Disks].AllowEdits = True
Else
Command29.Caption = "Locked"
Me.[Hard-Disks].AllowEdits = False
End If
End Sub


But this and many other variations I have tried, errors on the setting the parameter line.



If anyone could show me the right way to do this, I would be exceedingly grateful.


Sorry is this is such a newbie question, but still learning

Many thanks

Nigel
 

essaytee

Need a good one-liner.
Local time
Today, 18:21
Joined
Oct 20, 2008
Messages
512
Try this:

To refer to a page of a tab control, is as follows:

Me.tab_controlName.Pages(n).Caption

If I'm not mistaken, the AllowEdits refers to the the form generally, so the code would be Me.AllowEdits = true/false. If that is the case then no need to manipulate or worry about the tab control.

If you only want to disallow editing of a few controls, say on the tab page, use the "Locked" property "Me.ControlName.Locked = True/False" .
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:21
Joined
Feb 19, 2013
Messages
16,670
allowedits is a form property, not a control property
 

NigelFletcher

New member
Local time
Today, 09:21
Joined
Mar 7, 2019
Messages
5
Hi Steve, still not quite there,maybe because its 1:40 am lol
but its driving me crazy.

Looking at what you said
Me.tab_controlName.Pages(n).Caption

The Tabcontrol name TabCtl10
The Page Name is Hdisks

Im not sure on what (n) or Caption means
Is (n) the page index number?
In which case its 8
Is the caption the Name on the tab
Caption 'Hard Disks'


I have translated this to

If Command29.Caption = "Locked" Then
Command29.Caption = "Edit" 'Renaming the button
Me.TabbCtl0.Hdisks.Page(8).AllowEdits = True
Else
Command29.Caption = "Locked" 'Renaming the button
Me.TabbCtl0.Hdisks.Page(8).AllowEdits = False
End If

It errors on Me.TabbCtl0

Sorry to be a pain, but IM really trying to understand this and I do understand what CJ London said that it is a form property.

If you could spare me a few more minutes and let me know whats wrong with my code, again Id be so grateful

Many thanks

Nigel


Ps Got to go to bed now, nearly 2am, will check in the morning, thanks again for you help, very much appreciated.
 

June7

AWF VIP
Local time
Today, 00:21
Joined
Mar 9, 2014
Messages
5,493
As noted, AllowEdits is property of form, not Tab control nor its pages nor any other control.

If the Tab control page holds a subform then set that form's AllowEdits property. If the Tab control page holds textboxes and comboboxes, use Conditional Formatting to enable/disable them.

n would be the index reference for the Tab control page but is irrelevant for your purpose.

If user can lock/unlock for edit at will, why bother with locking to begin with?
 

essaytee

Need a good one-liner.
Local time
Today, 18:21
Joined
Oct 20, 2008
Messages
512
What June said.

Seems like we need to know a little more about what's on the page of your tab control, subform, listbox, textboxes etc and their purpose.

Code:
If Command29.Caption = "Locked" Then
    Command29.Caption = "Edit" 'Renaming the button
    [COLOR="Red"]'Me.TabbCtl0.Hdisks.Page(8).AllowEdits = True[/COLOR]
    [COLOR="Blue"]Me.AllowEdits = True[/COLOR]
Else
    Command29.Caption = "Locked" 'Renaming the button
    [COLOR="red"]'Me.TabbCtl0.Hdisks.Page(8).AllowEdits = False[/COLOR]
    [COLOR="Blue"]Me.AllowEdits = False[/COLOR]
End If

When referencing controls on any page of a Tab control, the fact that they are on a page of a Tab control has no bearing. If on page 2 of a Tab control you have a Textbox, "txtLastName", reference to that control is
Code:
me.txtLastName

In relation to the Tab control and the pages thereon, reference is made as previously suggested
Code:
Me.tab_controlName.Pages(n)
This is where intellisence is handy, type the dot and up pops all the available options. n is the page number, first page is zero.

Using your example in referencing the page of a Tab control
Code:
[COLOR="Red"]Me.TabbCtl0.Hdisks.Page(8)[/COLOR]            ' wrong  .AllowEdits = True

should be

[COLOR="Blue"]Me.TabbCt10.Pages(8)[/COLOR]        (then type a dot and see your options available)

Edit:
ps. You should get in the habit of meaningful names of controls.
 

NigelFletcher

New member
Local time
Today, 09:21
Joined
Mar 7, 2019
Messages
5
Morning Everyone,

Many thanks for all your help on this, Esaytee had it right, with just a very simple
me.allowedits = false/true.

I cant believe I spent so much time addressing controls and tabs etc and then posting on here and wasting peoples time, when the answer seems so simple. Trouble is you don't know its simple until someone tells you.

Really appreciate all your help, fabulous place and so pleased with all the responses. :)

Knowing there's a great community out there, just motivates me to do even more.

Once again Id like to say a very great thanks to everyone.

cheers

Nigel
 
Last edited:

Users who are viewing this thread

Top Bottom