Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I move the command button ? 1

Status
Not open for further replies.

MrAccess

Programmer
Apr 30, 2002
8
CN
I want to move a command button from the form's page footer to the page header, How Can I do thia with VBA code ?
 
Hi

There is a Section Property for the button:

Dim frm As Form
Dim btn As CommandButton
'
DoCmd.OpenForm "form1", acDesign
Set frm = Forms!Form1
Set btn = frm!command0
'
btn.Section = acHeader

but it is read only so you cannot set it in code.

The only way I can think to do it is to delete the button and then insert it in the header, this would (I think) mean deleting the code behind it and recreating that as well, if I have a spare 10mins today, I will try it.

But why do you want to do this?

Regards
Ken Reay
Freelance Developer
kenneth.reay@talk21.com
 
Aint gonna happen unless you want to use the API and some pretty hefty code. A control's 'section' property is read-only at runtime and you'd have to change it from acFooter to acHeader to move the button to the top, otherwise all you can do is move it around in its current section. Your best bet is to add two buttons that call the same function and toggle their visiblity as needed.

If your users can open the form in design view you can make this kind of change programmatically, but design view is usually off limits to end users if permissions are set up properly.

VBSlammer
 
Have two buttons that do the same thing (actually one can call the other's code)
Toggle their Visible property and you get the effect you want.

Regards,

Dan
[pipe]
 
Hi

You can 'move' the button, as I suggested by deleting and recreating.

Public Sub moveit()
Dim frm As Form, ctlNew As Control, btn As CommandButton, btnNew As CommandButton
Dim strName As String

' Create new form and get pointer to it.
DoCmd.OpenForm "Form1", acDesign
Set frm = Forms!Form1
Set btn = frm!Command0
strName = btn.Name
DeleteControl frm.Name, btn.Name
Set btnNew = CreateControl(frm.Name, acCommandButton, acHeader, "", , 1, 1, 500, 500)
btnNew.Name = strName
' Size control.
btnNew.SizeToFit


End Sub

but I do think the earlier suggestions ref have two buttons, amd switch their visible property is a much better way to achieve the desired result.

Regards
Ken Reay
Freelance Developer
kenneth.reay@talk21.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top