changing form/button properties from code

303factory

Registered User.
Local time
Today, 14:14
Joined
Oct 10, 2008
Messages
136
Hi

I'm trying to activate/deactivate the form control box, and change the position of some buttons by code, but it wont let me do either


TargetForm.ControlBox = False

TargetForm.CloseButton.Left = 12.354
TargetForm.CloseButton.Top = 0
TargetForm.CloseButton.Width = 0.593
TargetForm.CloseButton.Height = 0.593

Is there any reason I can change these values in form design mode but not with the code when it's running?

Thanks!

303
 
This should work - when do you want the code to execute and where from? If it is from the form on a button the code would be:

me!CloseButton.Height = 1000 (size works in pixels i think)
 
This should work - when do you want the code to execute and where from? If it is from the form on a button the code would be:

me!CloseButton.Height = 1000 (size works in pixels i think)

I've got the button positioning working by using pixels as suggested thanks!

Although I'm still stuck on activating/deactivating the control box

It's saying 'invalid qualifier'

The change is taking place from a module 'MainControl' in a sub that is called by the form load propery

Private Sub Form_Load()
Call initialiseSmallForm(Me)
End Sub

Public Sub InitialiseSmallForm(TargetForm As Form)

If getUser = "Admin" Then
TargetForm.ControlBox = True
Else
TargetForm.ControlBox.Value = False
End If

End Sub

Any ideas what I'm doing wrong?
 
try just

If getUser = "Admin" Then
TargetForm.ControlBox = True
Else
TargetForm.ControlBox = False
End If

if it wont work it might be because of the waybthe from parameter is being passed

in which case try putting your code inside the forms module, rather than as a global module, to see if it makes a difference
 
try just



if it wont work it might be because of the waybthe from parameter is being passed

in which case try putting your code inside the forms module, rather than as a global module, to see if it makes a difference

Tried it without the .Value and calling it from the form instead, and it's now saying 'you cant assign a value to this object'

maybe it's one of those things that cant be controlled by code..
 
it says you can in help

i am more inclined to think its because you aren't quite passing the form object in the correct way

thats why i suggested trying to do this directly in the forms open event to get the syntax correct.
 
Tried it without the .Value and calling it from the form instead, and it's now saying 'you cant assign a value to this object'

maybe it's one of those things that cant be controlled by code..

In the help it says you can only set this in design view:

Note Setting the ControlBox property to No also removes the Minimize, Maximize, and Close buttons on a form.
You can set this property by using the form's property sheet, a macro, or Visual Basic.
It can only be set in form Design view.
 
thats what it is then - although you can use VB, you have to open the from in design mode, change it and save it - so not so useful.

what does removing the control box achieve?

what are you trying to stop the users doing?
 
I suspect that what you need to do is look at the problem from the other direction.
  1. In Design View, set ControlBox to No
  2. Create command buttons for Minimize, Maximize, Close
  3. By default make these buttons invisible
Then add this code:

Code:
Private Sub Form_Load()
If getUser = "Admin" Then
 CloseButton.Visible = True 
 MaxButton.Visible = True
 MinButton.Visible = True
End If
End Sub

Now the command buttons will only be visible/available if the user is identified as "admins" when the for loads, other wise they'll not be visible/available.
 

Users who are viewing this thread

Back
Top Bottom