Maximize or minimize form with button

I

Imran Ghani

Hi! I am working with MS Access 2007 and VBA code. I want to make my form
minimize and maximize programmatically with the help of a command button. At
the same time, moreover, I would like to change the label of my button as
such to indicate the current position of the form, either it is maximized or
mininmized. I'll appreciate valuable help in this regards. Thanks in advance.
 
G

Graham Mandeno

Hi Imran

When you say "minimize", I assume you mean "restore". "Minimize" means
reduce it to an icon at the bottom of the screen or on the task bar, so you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not maximized, not
minimized) and you have a button named "cmdToggleMaximize" with the caption
"Maximize form", you need a Click event procedure for that button:

Private Sub cmdToggleMaximize_Click()
With cmdToggleMaximize
If .Caption = "Maximize form" Then
DoCmd.Maximize
.Caption = "Make me small again"
Else
DoCmd.Restore
.Caption = "Maximize form"
End If
End With
End Sub

This procedure checks the caption of the command button you have clicked to
see if the form needs maximizing or not. If so, it maximizes it and changes
the caption. If not, it restores it and changes the caption back again.
 
I

Imran Ghani

Thank you for your valuable help. The caption of the button is changing, but
the form is not maximizing or minimizing. I have default menu bars on my
Access 2007 form. I'd be very greatful if you could indicate about deficiency
which is not letting me make my form maximize or minimize by the use of the
command button. Is there any other way that we can programmatically change
the dimensions of the form by clicking on the button. I am a novice and hence
appreciate your cooperation. Also please guide me about how to remove the
default menu items from the application.

Graham Mandeno said:
Hi Imran

When you say "minimize", I assume you mean "restore". "Minimize" means
reduce it to an icon at the bottom of the screen or on the task bar, so you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not maximized, not
minimized) and you have a button named "cmdToggleMaximize" with the caption
"Maximize form", you need a Click event procedure for that button:

Private Sub cmdToggleMaximize_Click()
With cmdToggleMaximize
If .Caption = "Maximize form" Then
DoCmd.Maximize
.Caption = "Make me small again"
Else
DoCmd.Restore
.Caption = "Maximize form"
End If
End With
End Sub

This procedure checks the caption of the command button you have clicked to
see if the form needs maximizing or not. If so, it maximizes it and changes
the caption. If not, it restores it and changes the caption back again.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Imran Ghani said:
Hi! I am working with MS Access 2007 and VBA code. I want to make my form
minimize and maximize programmatically with the help of a command button.
At
the same time, moreover, I would like to change the label of my button as
such to indicate the current position of the form, either it is maximized
or
mininmized. I'll appreciate valuable help in this regards. Thanks in
advance.
 
G

Graham Mandeno

Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not to be working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure, and see if it
works then?

For moving and resizing the form, check out DoCmd.MoveSize method, and also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and properties is
the "TWIP". Are TWIP is a "twentieth of a point", which means there are
1440 per inch.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Imran Ghani said:
Thank you for your valuable help. The caption of the button is changing,
but
the form is not maximizing or minimizing. I have default menu bars on my
Access 2007 form. I'd be very greatful if you could indicate about
deficiency
which is not letting me make my form maximize or minimize by the use of
the
command button. Is there any other way that we can programmatically change
the dimensions of the form by clicking on the button. I am a novice and
hence
appreciate your cooperation. Also please guide me about how to remove the
default menu items from the application.

Graham Mandeno said:
Hi Imran

When you say "minimize", I assume you mean "restore". "Minimize" means
reduce it to an icon at the bottom of the screen or on the task bar, so
you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not maximized, not
minimized) and you have a button named "cmdToggleMaximize" with the
caption
"Maximize form", you need a Click event procedure for that button:

Private Sub cmdToggleMaximize_Click()
With cmdToggleMaximize
If .Caption = "Maximize form" Then
DoCmd.Maximize
.Caption = "Make me small again"
Else
DoCmd.Restore
.Caption = "Maximize form"
End If
End With
End Sub

This procedure checks the caption of the command button you have clicked
to
see if the form needs maximizing or not. If so, it maximizes it and
changes
the caption. If not, it restores it and changes the caption back again.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Imran Ghani said:
Hi! I am working with MS Access 2007 and VBA code. I want to make my
form
minimize and maximize programmatically with the help of a command
button.
At
the same time, moreover, I would like to change the label of my button
as
such to indicate the current position of the form, either it is
maximized
or
mininmized. I'll appreciate valuable help in this regards. Thanks in
advance.
 
I

Imran Ghani

Thanks for your advise. Please also guide, if it is due to the fact that I am
using the default menus. Do the menus have something to do with the forms'
maximizing and restoring properties. Do I have to also refer to the form's
name also when using maximizing or restoring propereties ?

Graham Mandeno said:
Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not to be working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure, and see if it
works then?

For moving and resizing the form, check out DoCmd.MoveSize method, and also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and properties is
the "TWIP". Are TWIP is a "twentieth of a point", which means there are
1440 per inch.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Imran Ghani said:
Thank you for your valuable help. The caption of the button is changing,
but
the form is not maximizing or minimizing. I have default menu bars on my
Access 2007 form. I'd be very greatful if you could indicate about
deficiency
which is not letting me make my form maximize or minimize by the use of
the
command button. Is there any other way that we can programmatically change
the dimensions of the form by clicking on the button. I am a novice and
hence
appreciate your cooperation. Also please guide me about how to remove the
default menu items from the application.

Graham Mandeno said:
Hi Imran

When you say "minimize", I assume you mean "restore". "Minimize" means
reduce it to an icon at the bottom of the screen or on the task bar, so
you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not maximized, not
minimized) and you have a button named "cmdToggleMaximize" with the
caption
"Maximize form", you need a Click event procedure for that button:

Private Sub cmdToggleMaximize_Click()
With cmdToggleMaximize
If .Caption = "Maximize form" Then
DoCmd.Maximize
.Caption = "Make me small again"
Else
DoCmd.Restore
.Caption = "Maximize form"
End If
End With
End Sub

This procedure checks the caption of the command button you have clicked
to
see if the form needs maximizing or not. If so, it maximizes it and
changes
the caption. If not, it restores it and changes the caption back again.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi! I am working with MS Access 2007 and VBA code. I want to make my
form
minimize and maximize programmatically with the help of a command
button.
At
the same time, moreover, I would like to change the label of my button
as
such to indicate the current position of the form, either it is
maximized
or
mininmized. I'll appreciate valuable help in this regards. Thanks in
advance.
 
I

Imran Ghani

Thanks for your guidance. Please guide me if we can also change the picture
of the command button also indicating the maximize and minimize position
along with changing the form position. Is there any specific property of the
form which should also be enabled for the form to be maximized or restored?

Graham Mandeno said:
Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not to be working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure, and see if it
works then?

For moving and resizing the form, check out DoCmd.MoveSize method, and also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and properties is
the "TWIP". Are TWIP is a "twentieth of a point", which means there are
1440 per inch.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Imran Ghani said:
Thank you for your valuable help. The caption of the button is changing,
but
the form is not maximizing or minimizing. I have default menu bars on my
Access 2007 form. I'd be very greatful if you could indicate about
deficiency
which is not letting me make my form maximize or minimize by the use of
the
command button. Is there any other way that we can programmatically change
the dimensions of the form by clicking on the button. I am a novice and
hence
appreciate your cooperation. Also please guide me about how to remove the
default menu items from the application.

Graham Mandeno said:
Hi Imran

When you say "minimize", I assume you mean "restore". "Minimize" means
reduce it to an icon at the bottom of the screen or on the task bar, so
you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not maximized, not
minimized) and you have a button named "cmdToggleMaximize" with the
caption
"Maximize form", you need a Click event procedure for that button:

Private Sub cmdToggleMaximize_Click()
With cmdToggleMaximize
If .Caption = "Maximize form" Then
DoCmd.Maximize
.Caption = "Make me small again"
Else
DoCmd.Restore
.Caption = "Maximize form"
End If
End With
End Sub

This procedure checks the caption of the command button you have clicked
to
see if the form needs maximizing or not. If so, it maximizes it and
changes
the caption. If not, it restores it and changes the caption back again.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi! I am working with MS Access 2007 and VBA code. I want to make my
form
minimize and maximize programmatically with the help of a command
button.
At
the same time, moreover, I would like to change the label of my button
as
such to indicate the current position of the form, either it is
maximized
or
mininmized. I'll appreciate valuable help in this regards. Thanks in
advance.
 
G

Graham Mandeno

Hi Imran

Whether or not you use default menus on the form should have no bearing on
moving or resizing the form.

The DoCmd methods (Maximize, Minimize, Restore and MoveSize) affect the
currently active window, so you don't need to specify a form.

InsideHeight and InsideWidth are properties of a form object, so should be
qualified by a reference to a form - either Forms![FormName] or
Forms("FormName") or, if the code is in the form's own class module, Me.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Imran Ghani said:
Thanks for your advise. Please also guide, if it is due to the fact that I
am
using the default menus. Do the menus have something to do with the forms'
maximizing and restoring properties. Do I have to also refer to the form's
name also when using maximizing or restoring propereties ?

Graham Mandeno said:
Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not to be
working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure, and see if it
works then?

For moving and resizing the form, check out DoCmd.MoveSize method, and
also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and properties
is
the "TWIP". Are TWIP is a "twentieth of a point", which means there are
1440 per inch.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Imran Ghani said:
Thank you for your valuable help. The caption of the button is
changing,
but
the form is not maximizing or minimizing. I have default menu bars on
my
Access 2007 form. I'd be very greatful if you could indicate about
deficiency
which is not letting me make my form maximize or minimize by the use of
the
command button. Is there any other way that we can programmatically
change
the dimensions of the form by clicking on the button. I am a novice and
hence
appreciate your cooperation. Also please guide me about how to remove
the
default menu items from the application.

:

Hi Imran

When you say "minimize", I assume you mean "restore". "Minimize"
means
reduce it to an icon at the bottom of the screen or on the task bar,
so
you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not maximized, not
minimized) and you have a button named "cmdToggleMaximize" with the
caption
"Maximize form", you need a Click event procedure for that button:

Private Sub cmdToggleMaximize_Click()
With cmdToggleMaximize
If .Caption = "Maximize form" Then
DoCmd.Maximize
.Caption = "Make me small again"
Else
DoCmd.Restore
.Caption = "Maximize form"
End If
End With
End Sub

This procedure checks the caption of the command button you have
clicked
to
see if the form needs maximizing or not. If so, it maximizes it and
changes
the caption. If not, it restores it and changes the caption back
again.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi! I am working with MS Access 2007 and VBA code. I want to make my
form
minimize and maximize programmatically with the help of a command
button.
At
the same time, moreover, I would like to change the label of my
button
as
such to indicate the current position of the form, either it is
maximized
or
mininmized. I'll appreciate valuable help in this regards. Thanks in
advance.
 
G

Graham Mandeno

Hi Imran

I have not used pictures on command buttons as they are a new feature of
Access 2007. However, I believe you should be able to change them at
run-time simply by assigning another image file name to the Picture
property:

Me.cmdMyButton.Picture = "C:\Icons\NewIcon.ico"

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Imran Ghani said:
Thanks for your guidance. Please guide me if we can also change the
picture
of the command button also indicating the maximize and minimize position
along with changing the form position. Is there any specific property of
the
form which should also be enabled for the form to be maximized or
restored?

Graham Mandeno said:
Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not to be
working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure, and see if it
works then?

For moving and resizing the form, check out DoCmd.MoveSize method, and
also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and properties
is
the "TWIP". Are TWIP is a "twentieth of a point", which means there are
1440 per inch.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Imran Ghani said:
Thank you for your valuable help. The caption of the button is
changing,
but
the form is not maximizing or minimizing. I have default menu bars on
my
Access 2007 form. I'd be very greatful if you could indicate about
deficiency
which is not letting me make my form maximize or minimize by the use of
the
command button. Is there any other way that we can programmatically
change
the dimensions of the form by clicking on the button. I am a novice and
hence
appreciate your cooperation. Also please guide me about how to remove
the
default menu items from the application.

:

Hi Imran

When you say "minimize", I assume you mean "restore". "Minimize"
means
reduce it to an icon at the bottom of the screen or on the task bar,
so
you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not maximized, not
minimized) and you have a button named "cmdToggleMaximize" with the
caption
"Maximize form", you need a Click event procedure for that button:

Private Sub cmdToggleMaximize_Click()
With cmdToggleMaximize
If .Caption = "Maximize form" Then
DoCmd.Maximize
.Caption = "Make me small again"
Else
DoCmd.Restore
.Caption = "Maximize form"
End If
End With
End Sub

This procedure checks the caption of the command button you have
clicked
to
see if the form needs maximizing or not. If so, it maximizes it and
changes
the caption. If not, it restores it and changes the caption back
again.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi! I am working with MS Access 2007 and VBA code. I want to make my
form
minimize and maximize programmatically with the help of a command
button.
At
the same time, moreover, I would like to change the label of my
button
as
such to indicate the current position of the form, either it is
maximized
or
mininmized. I'll appreciate valuable help in this regards. Thanks in
advance.
 
I

Imran Ghani

Thanks for your kind help. Your code worked perfectly with the form's
maximized and restored positions. Actually the properties set in my form were
not allowing the code to work. I have changed the properties and hence it is
all working now. Can you please also guide regarding if I want to bring all
the forms' contents in centre of the form when the form is in restored
position. For the time being the contents of the form are not in the centre
of the screen when its in restored position.I also want to bring all the
other forms in my application to the same position, either restored or
maximized, as the main form. What sort of coding or properties do I need to
set to accomplish my goal.

Graham Mandeno said:
Hi Imran

I have not used pictures on command buttons as they are a new feature of
Access 2007. However, I believe you should be able to change them at
run-time simply by assigning another image file name to the Picture
property:

Me.cmdMyButton.Picture = "C:\Icons\NewIcon.ico"

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Imran Ghani said:
Thanks for your guidance. Please guide me if we can also change the
picture
of the command button also indicating the maximize and minimize position
along with changing the form position. Is there any specific property of
the
form which should also be enabled for the form to be maximized or
restored?

Graham Mandeno said:
Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not to be
working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure, and see if it
works then?

For moving and resizing the form, check out DoCmd.MoveSize method, and
also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and properties
is
the "TWIP". Are TWIP is a "twentieth of a point", which means there are
1440 per inch.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Thank you for your valuable help. The caption of the button is
changing,
but
the form is not maximizing or minimizing. I have default menu bars on
my
Access 2007 form. I'd be very greatful if you could indicate about
deficiency
which is not letting me make my form maximize or minimize by the use of
the
command button. Is there any other way that we can programmatically
change
the dimensions of the form by clicking on the button. I am a novice and
hence
appreciate your cooperation. Also please guide me about how to remove
the
default menu items from the application.

:

Hi Imran

When you say "minimize", I assume you mean "restore". "Minimize"
means
reduce it to an icon at the bottom of the screen or on the task bar,
so
you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not maximized, not
minimized) and you have a button named "cmdToggleMaximize" with the
caption
"Maximize form", you need a Click event procedure for that button:

Private Sub cmdToggleMaximize_Click()
With cmdToggleMaximize
If .Caption = "Maximize form" Then
DoCmd.Maximize
.Caption = "Make me small again"
Else
DoCmd.Restore
.Caption = "Maximize form"
End If
End With
End Sub

This procedure checks the caption of the command button you have
clicked
to
see if the form needs maximizing or not. If so, it maximizes it and
changes
the caption. If not, it restores it and changes the caption back
again.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi! I am working with MS Access 2007 and VBA code. I want to make my
form
minimize and maximize programmatically with the help of a command
button.
At
the same time, moreover, I would like to change the label of my
button
as
such to indicate the current position of the form, either it is
maximized
or
mininmized. I'll appreciate valuable help in this regards. Thanks in
advance.
 
G

Graham Mandeno

Hi Imran

I'm glad you got the Maximize/Restore working :)

If you set the form's AutoCenter property to "Yes" then the form should
center itself when it is opened. If you then maximize it and subsequently
restore it, it should revert to its previous position.

However, if you drag it to another location, then maximize/restore it, it
will stay in that new location.

If you want it to re-center itself when it is restored, then you will
require some much more serious code. Do you really want to go there?
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Imran Ghani said:
Thanks for your kind help. Your code worked perfectly with the form's
maximized and restored positions. Actually the properties set in my form
were
not allowing the code to work. I have changed the properties and hence it
is
all working now. Can you please also guide regarding if I want to bring
all
the forms' contents in centre of the form when the form is in restored
position. For the time being the contents of the form are not in the
centre
of the screen when its in restored position.I also want to bring all the
other forms in my application to the same position, either restored or
maximized, as the main form. What sort of coding or properties do I need
to
set to accomplish my goal.

Graham Mandeno said:
Hi Imran

I have not used pictures on command buttons as they are a new feature of
Access 2007. However, I believe you should be able to change them at
run-time simply by assigning another image file name to the Picture
property:

Me.cmdMyButton.Picture = "C:\Icons\NewIcon.ico"

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Imran Ghani said:
Thanks for your guidance. Please guide me if we can also change the
picture
of the command button also indicating the maximize and minimize
position
along with changing the form position. Is there any specific property
of
the
form which should also be enabled for the form to be maximized or
restored?

:

Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not to be
working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure, and see if
it
works then?

For moving and resizing the form, check out DoCmd.MoveSize method, and
also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and
properties
is
the "TWIP". Are TWIP is a "twentieth of a point", which means there
are
1440 per inch.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Thank you for your valuable help. The caption of the button is
changing,
but
the form is not maximizing or minimizing. I have default menu bars
on
my
Access 2007 form. I'd be very greatful if you could indicate about
deficiency
which is not letting me make my form maximize or minimize by the use
of
the
command button. Is there any other way that we can programmatically
change
the dimensions of the form by clicking on the button. I am a novice
and
hence
appreciate your cooperation. Also please guide me about how to
remove
the
default menu items from the application.

:

Hi Imran

When you say "minimize", I assume you mean "restore". "Minimize"
means
reduce it to an icon at the bottom of the screen or on the task
bar,
so
you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not maximized,
not
minimized) and you have a button named "cmdToggleMaximize" with the
caption
"Maximize form", you need a Click event procedure for that button:

Private Sub cmdToggleMaximize_Click()
With cmdToggleMaximize
If .Caption = "Maximize form" Then
DoCmd.Maximize
.Caption = "Make me small again"
Else
DoCmd.Restore
.Caption = "Maximize form"
End If
End With
End Sub

This procedure checks the caption of the command button you have
clicked
to
see if the form needs maximizing or not. If so, it maximizes it
and
changes
the caption. If not, it restores it and changes the caption back
again.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

message
Hi! I am working with MS Access 2007 and VBA code. I want to make
my
form
minimize and maximize programmatically with the help of a command
button.
At
the same time, moreover, I would like to change the label of my
button
as
such to indicate the current position of the form, either it is
maximized
or
mininmized. I'll appreciate valuable help in this regards. Thanks
in
advance.
 
I

Imran Ghani

Thanks indeed for your helpful advise. I do want to make my form to re-center
itself when it is restored. I'd appreciate much your help in this regards.
Yes, I'd like to code the form for the same purpose. Please go ahead with
your helpful code for this purpose.

Graham Mandeno said:
Hi Imran

I'm glad you got the Maximize/Restore working :)

If you set the form's AutoCenter property to "Yes" then the form should
center itself when it is opened. If you then maximize it and subsequently
restore it, it should revert to its previous position.

However, if you drag it to another location, then maximize/restore it, it
will stay in that new location.

If you want it to re-center itself when it is restored, then you will
require some much more serious code. Do you really want to go there?
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Imran Ghani said:
Thanks for your kind help. Your code worked perfectly with the form's
maximized and restored positions. Actually the properties set in my form
were
not allowing the code to work. I have changed the properties and hence it
is
all working now. Can you please also guide regarding if I want to bring
all
the forms' contents in centre of the form when the form is in restored
position. For the time being the contents of the form are not in the
centre
of the screen when its in restored position.I also want to bring all the
other forms in my application to the same position, either restored or
maximized, as the main form. What sort of coding or properties do I need
to
set to accomplish my goal.

Graham Mandeno said:
Hi Imran

I have not used pictures on command buttons as they are a new feature of
Access 2007. However, I believe you should be able to change them at
run-time simply by assigning another image file name to the Picture
property:

Me.cmdMyButton.Picture = "C:\Icons\NewIcon.ico"

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Thanks for your guidance. Please guide me if we can also change the
picture
of the command button also indicating the maximize and minimize
position
along with changing the form position. Is there any specific property
of
the
form which should also be enabled for the form to be maximized or
restored?

:

Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not to be
working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure, and see if
it
works then?

For moving and resizing the form, check out DoCmd.MoveSize method, and
also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and
properties
is
the "TWIP". Are TWIP is a "twentieth of a point", which means there
are
1440 per inch.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Thank you for your valuable help. The caption of the button is
changing,
but
the form is not maximizing or minimizing. I have default menu bars
on
my
Access 2007 form. I'd be very greatful if you could indicate about
deficiency
which is not letting me make my form maximize or minimize by the use
of
the
command button. Is there any other way that we can programmatically
change
the dimensions of the form by clicking on the button. I am a novice
and
hence
appreciate your cooperation. Also please guide me about how to
remove
the
default menu items from the application.

:

Hi Imran

When you say "minimize", I assume you mean "restore". "Minimize"
means
reduce it to an icon at the bottom of the screen or on the task
bar,
so
you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not maximized,
not
minimized) and you have a button named "cmdToggleMaximize" with the
caption
"Maximize form", you need a Click event procedure for that button:

Private Sub cmdToggleMaximize_Click()
With cmdToggleMaximize
If .Caption = "Maximize form" Then
DoCmd.Maximize
.Caption = "Make me small again"
Else
DoCmd.Restore
.Caption = "Maximize form"
End If
End With
End Sub

This procedure checks the caption of the command button you have
clicked
to
see if the form needs maximizing or not. If so, it maximizes it
and
changes
the caption. If not, it restores it and changes the caption back
again.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

message
Hi! I am working with MS Access 2007 and VBA code. I want to make
my
form
minimize and maximize programmatically with the help of a command
button.
At
the same time, moreover, I would like to change the label of my
button
as
such to indicate the current position of the form, either it is
maximized
or
mininmized. I'll appreciate valuable help in this regards. Thanks
in
advance.
 
I

Imran Ghani

Thanks for your help. I want to make my form to re-center
itself when it is restored and I'd also like that the other forms in my
application should also be restored when the main form is in the restored
position, same should be the case other way around when the main form is
maximized. I'd appreciate much your help in this regards.


Graham Mandeno said:
Hi Imran

I'm glad you got the Maximize/Restore working :)

If you set the form's AutoCenter property to "Yes" then the form should
center itself when it is opened. If you then maximize it and subsequently
restore it, it should revert to its previous position.

However, if you drag it to another location, then maximize/restore it, it
will stay in that new location.

If you want it to re-center itself when it is restored, then you will
require some much more serious code. Do you really want to go there?
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Imran Ghani said:
Thanks for your kind help. Your code worked perfectly with the form's
maximized and restored positions. Actually the properties set in my form
were
not allowing the code to work. I have changed the properties and hence it
is
all working now. Can you please also guide regarding if I want to bring
all
the forms' contents in centre of the form when the form is in restored
position. For the time being the contents of the form are not in the
centre
of the screen when its in restored position.I also want to bring all the
other forms in my application to the same position, either restored or
maximized, as the main form. What sort of coding or properties do I need
to
set to accomplish my goal.

Graham Mandeno said:
Hi Imran

I have not used pictures on command buttons as they are a new feature of
Access 2007. However, I believe you should be able to change them at
run-time simply by assigning another image file name to the Picture
property:

Me.cmdMyButton.Picture = "C:\Icons\NewIcon.ico"

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Thanks for your guidance. Please guide me if we can also change the
picture
of the command button also indicating the maximize and minimize
position
along with changing the form position. Is there any specific property
of
the
form which should also be enabled for the form to be maximized or
restored?

:

Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not to be
working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure, and see if
it
works then?

For moving and resizing the form, check out DoCmd.MoveSize method, and
also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and
properties
is
the "TWIP". Are TWIP is a "twentieth of a point", which means there
are
1440 per inch.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Thank you for your valuable help. The caption of the button is
changing,
but
the form is not maximizing or minimizing. I have default menu bars
on
my
Access 2007 form. I'd be very greatful if you could indicate about
deficiency
which is not letting me make my form maximize or minimize by the use
of
the
command button. Is there any other way that we can programmatically
change
the dimensions of the form by clicking on the button. I am a novice
and
hence
appreciate your cooperation. Also please guide me about how to
remove
the
default menu items from the application.

:

Hi Imran

When you say "minimize", I assume you mean "restore". "Minimize"
means
reduce it to an icon at the bottom of the screen or on the task
bar,
so
you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not maximized,
not
minimized) and you have a button named "cmdToggleMaximize" with the
caption
"Maximize form", you need a Click event procedure for that button:

Private Sub cmdToggleMaximize_Click()
With cmdToggleMaximize
If .Caption = "Maximize form" Then
DoCmd.Maximize
.Caption = "Make me small again"
Else
DoCmd.Restore
.Caption = "Maximize form"
End If
End With
End Sub

This procedure checks the caption of the command button you have
clicked
to
see if the form needs maximizing or not. If so, it maximizes it
and
changes
the caption. If not, it restores it and changes the caption back
again.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

message
Hi! I am working with MS Access 2007 and VBA code. I want to make
my
form
minimize and maximize programmatically with the help of a command
button.
At
the same time, moreover, I would like to change the label of my
button
as
such to indicate the current position of the form, either it is
maximized
or
mininmized. I'll appreciate valuable help in this regards. Thanks
in
advance.
 
G

Graham Mandeno

Hi Imran

Well, I warned you the code was serious! :)

Copy the code below and paste it into a new, empty module.

Then you can call the function winCenterInMDI from your form code, passing
the handle of the form's window like this:

Call winCenterInMDI(Me.hWnd)

If the form is already maximized or minimized, then it will be restored,
then it will be centered in the Access window.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

========== start code ===============
Option Compare Text
Option Explicit

Private Const cMaxBuffer = 255

Private Declare Function apiGetClassName _
Lib "user32" _
Alias "GetClassNameA" _
(ByVal hWnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) _
As Long

Private Declare Function apiGetWindow _
Lib "user32" _
Alias "GetWindow" _
(ByVal hWnd As Long, _
ByVal wCmd As Long) _
As Long

Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

Private Declare Function apiShowWindow _
Lib "user32" _
Alias "ShowWindow" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) _
As Long

Private Const SW_RESTORE = 9

Private Declare Function apiIsZoomed _
Lib "user32" _
Alias "IsZoomed" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiIsIconic _
Lib "user32" _
Alias "IsIconic" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiMoveWindow _
Lib "user32" _
Alias "MoveWindow" _
(ByVal hWnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) _
As Long

Private Type winRECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function apiGetWindowRect _
Lib "user32" _
Alias "GetWindowRect" _
(ByVal hWnd As Long, _
lpRect As winRECT) _
As Long

Public Function winGetHWndMDI(Optional hWndApp As Long) As Long
Dim hWnd As Long
winGetHWndMDI = 0
If hWndApp = 0 Then hWndApp = Application.hWndAccessApp
hWnd = apiGetWindow(hWndApp, GW_CHILD)
Do Until hWnd = 0
If winGetClassName(hWnd) = "MDIClient" Then
winGetHWndMDI = hWnd
Exit Do
End If
hWnd = apiGetWindow(hWnd, GW_HWNDNEXT)
Loop
End Function

Public Function winGetClassName(hWnd As Long) As String
Dim sBuffer As String, iLen As Integer
sBuffer = String$(cMaxBuffer - 1, 0)
iLen = apiGetClassName(hWnd, sBuffer, cMaxBuffer)
If iLen > 0 Then
winGetClassName = Left$(sBuffer, iLen)
End If
End Function

Public Function winCenterInMDI(hWnd As Long)
Dim MDIRect As winRECT, WndRect As winRECT
Dim lNewTop As Long, lNewLeft As Long
Dim lHeight As Long, lWidth As Long
' If the form is maximized, restore it.
If apiIsZoomed(hWnd) <> 0 Or apiIsIconic(hWnd) <> 0 Then
apiShowWindow hWnd, SW_RESTORE
End If
' Get the window size of the MDIClient window.
apiGetWindowRect winGetHWndMDI, MDIRect
' Get the window size of the MDIClient window.
apiGetWindowRect hWnd, WndRect
' Calculate Height and Width of window we are moving
With WndRect
lHeight = .Bottom - .Top
lWidth = .Right - .Left
End With
' Calculate new Top and Left coordinates
With MDIRect
lNewTop = (.Bottom - .Top - lHeight) / 2
lNewLeft = (.Right - .Left - lWidth) / 2
End With
' Move the window to the new position
apiMoveWindow hWnd, lNewLeft, lNewTop, lWidth, lHeight, True
End Function
========== end code ===============

Imran Ghani said:
Thanks indeed for your helpful advise. I do want to make my form to
re-center
itself when it is restored. I'd appreciate much your help in this regards.
Yes, I'd like to code the form for the same purpose. Please go ahead with
your helpful code for this purpose.

Graham Mandeno said:
Hi Imran

I'm glad you got the Maximize/Restore working :)

If you set the form's AutoCenter property to "Yes" then the form should
center itself when it is opened. If you then maximize it and
subsequently
restore it, it should revert to its previous position.

However, if you drag it to another location, then maximize/restore it, it
will stay in that new location.

If you want it to re-center itself when it is restored, then you will
require some much more serious code. Do you really want to go there?
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Imran Ghani said:
Thanks for your kind help. Your code worked perfectly with the form's
maximized and restored positions. Actually the properties set in my
form
were
not allowing the code to work. I have changed the properties and hence
it
is
all working now. Can you please also guide regarding if I want to bring
all
the forms' contents in centre of the form when the form is in restored
position. For the time being the contents of the form are not in the
centre
of the screen when its in restored position.I also want to bring all
the
other forms in my application to the same position, either restored or
maximized, as the main form. What sort of coding or properties do I
need
to
set to accomplish my goal.

:

Hi Imran

I have not used pictures on command buttons as they are a new feature
of
Access 2007. However, I believe you should be able to change them at
run-time simply by assigning another image file name to the Picture
property:

Me.cmdMyButton.Picture = "C:\Icons\NewIcon.ico"

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Thanks for your guidance. Please guide me if we can also change the
picture
of the command button also indicating the maximize and minimize
position
along with changing the form position. Is there any specific
property
of
the
form which should also be enabled for the form to be maximized or
restored?

:

Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not to be
working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure, and see
if
it
works then?

For moving and resizing the form, check out DoCmd.MoveSize method,
and
also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and
properties
is
the "TWIP". Are TWIP is a "twentieth of a point", which means
there
are
1440 per inch.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


message
Thank you for your valuable help. The caption of the button is
changing,
but
the form is not maximizing or minimizing. I have default menu
bars
on
my
Access 2007 form. I'd be very greatful if you could indicate
about
deficiency
which is not letting me make my form maximize or minimize by the
use
of
the
command button. Is there any other way that we can
programmatically
change
the dimensions of the form by clicking on the button. I am a
novice
and
hence
appreciate your cooperation. Also please guide me about how to
remove
the
default menu items from the application.

:

Hi Imran

When you say "minimize", I assume you mean "restore".
"Minimize"
means
reduce it to an icon at the bottom of the screen or on the task
bar,
so
you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not maximized,
not
minimized) and you have a button named "cmdToggleMaximize" with
the
caption
"Maximize form", you need a Click event procedure for that
button:

Private Sub cmdToggleMaximize_Click()
With cmdToggleMaximize
If .Caption = "Maximize form" Then
DoCmd.Maximize
.Caption = "Make me small again"
Else
DoCmd.Restore
.Caption = "Maximize form"
End If
End With
End Sub

This procedure checks the caption of the command button you have
clicked
to
see if the form needs maximizing or not. If so, it maximizes it
and
changes
the caption. If not, it restores it and changes the caption
back
again.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

message
Hi! I am working with MS Access 2007 and VBA code. I want to
make
my
form
minimize and maximize programmatically with the help of a
command
button.
At
the same time, moreover, I would like to change the label of
my
button
as
such to indicate the current position of the form, either it
is
maximized
or
mininmized. I'll appreciate valuable help in this regards.
Thanks
in
advance.
 
I

Imran Ghani

Hi Mandeno!
Thanks a lot for your very helpful code. The code is indeed working great
when the form is in the Restored state, but when it is maximized again the
contents do not come in the center. Please do guide me for what type of
settings I have to look for. Are there any specific settings I have to have,
apart from the function call. I am having my call function code in the form
current code. I'd appreciate your kind help in this regards.

Graham Mandeno said:
Hi Imran

Well, I warned you the code was serious! :)

Copy the code below and paste it into a new, empty module.

Then you can call the function winCenterInMDI from your form code, passing
the handle of the form's window like this:

Call winCenterInMDI(Me.hWnd)

If the form is already maximized or minimized, then it will be restored,
then it will be centered in the Access window.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

========== start code ===============
Option Compare Text
Option Explicit

Private Const cMaxBuffer = 255

Private Declare Function apiGetClassName _
Lib "user32" _
Alias "GetClassNameA" _
(ByVal hWnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) _
As Long

Private Declare Function apiGetWindow _
Lib "user32" _
Alias "GetWindow" _
(ByVal hWnd As Long, _
ByVal wCmd As Long) _
As Long

Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

Private Declare Function apiShowWindow _
Lib "user32" _
Alias "ShowWindow" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) _
As Long

Private Const SW_RESTORE = 9

Private Declare Function apiIsZoomed _
Lib "user32" _
Alias "IsZoomed" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiIsIconic _
Lib "user32" _
Alias "IsIconic" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiMoveWindow _
Lib "user32" _
Alias "MoveWindow" _
(ByVal hWnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) _
As Long

Private Type winRECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function apiGetWindowRect _
Lib "user32" _
Alias "GetWindowRect" _
(ByVal hWnd As Long, _
lpRect As winRECT) _
As Long

Public Function winGetHWndMDI(Optional hWndApp As Long) As Long
Dim hWnd As Long
winGetHWndMDI = 0
If hWndApp = 0 Then hWndApp = Application.hWndAccessApp
hWnd = apiGetWindow(hWndApp, GW_CHILD)
Do Until hWnd = 0
If winGetClassName(hWnd) = "MDIClient" Then
winGetHWndMDI = hWnd
Exit Do
End If
hWnd = apiGetWindow(hWnd, GW_HWNDNEXT)
Loop
End Function

Public Function winGetClassName(hWnd As Long) As String
Dim sBuffer As String, iLen As Integer
sBuffer = String$(cMaxBuffer - 1, 0)
iLen = apiGetClassName(hWnd, sBuffer, cMaxBuffer)
If iLen > 0 Then
winGetClassName = Left$(sBuffer, iLen)
End If
End Function

Public Function winCenterInMDI(hWnd As Long)
Dim MDIRect As winRECT, WndRect As winRECT
Dim lNewTop As Long, lNewLeft As Long
Dim lHeight As Long, lWidth As Long
' If the form is maximized, restore it.
If apiIsZoomed(hWnd) <> 0 Or apiIsIconic(hWnd) <> 0 Then
apiShowWindow hWnd, SW_RESTORE
End If
' Get the window size of the MDIClient window.
apiGetWindowRect winGetHWndMDI, MDIRect
' Get the window size of the MDIClient window.
apiGetWindowRect hWnd, WndRect
' Calculate Height and Width of window we are moving
With WndRect
lHeight = .Bottom - .Top
lWidth = .Right - .Left
End With
' Calculate new Top and Left coordinates
With MDIRect
lNewTop = (.Bottom - .Top - lHeight) / 2
lNewLeft = (.Right - .Left - lWidth) / 2
End With
' Move the window to the new position
apiMoveWindow hWnd, lNewLeft, lNewTop, lWidth, lHeight, True
End Function
========== end code ===============

Imran Ghani said:
Thanks indeed for your helpful advise. I do want to make my form to
re-center
itself when it is restored. I'd appreciate much your help in this regards.
Yes, I'd like to code the form for the same purpose. Please go ahead with
your helpful code for this purpose.

Graham Mandeno said:
Hi Imran

I'm glad you got the Maximize/Restore working :)

If you set the form's AutoCenter property to "Yes" then the form should
center itself when it is opened. If you then maximize it and
subsequently
restore it, it should revert to its previous position.

However, if you drag it to another location, then maximize/restore it, it
will stay in that new location.

If you want it to re-center itself when it is restored, then you will
require some much more serious code. Do you really want to go there?
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Thanks for your kind help. Your code worked perfectly with the form's
maximized and restored positions. Actually the properties set in my
form
were
not allowing the code to work. I have changed the properties and hence
it
is
all working now. Can you please also guide regarding if I want to bring
all
the forms' contents in centre of the form when the form is in restored
position. For the time being the contents of the form are not in the
centre
of the screen when its in restored position.I also want to bring all
the
other forms in my application to the same position, either restored or
maximized, as the main form. What sort of coding or properties do I
need
to
set to accomplish my goal.

:

Hi Imran

I have not used pictures on command buttons as they are a new feature
of
Access 2007. However, I believe you should be able to change them at
run-time simply by assigning another image file name to the Picture
property:

Me.cmdMyButton.Picture = "C:\Icons\NewIcon.ico"

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Thanks for your guidance. Please guide me if we can also change the
picture
of the command button also indicating the maximize and minimize
position
along with changing the form position. Is there any specific
property
of
the
form which should also be enabled for the form to be maximized or
restored?

:

Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not to be
working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure, and see
if
it
works then?

For moving and resizing the form, check out DoCmd.MoveSize method,
and
also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and
properties
is
the "TWIP". Are TWIP is a "twentieth of a point", which means
there
are
1440 per inch.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


message
Thank you for your valuable help. The caption of the button is
changing,
but
the form is not maximizing or minimizing. I have default menu
bars
on
my
Access 2007 form. I'd be very greatful if you could indicate
about
deficiency
which is not letting me make my form maximize or minimize by the
use
of
the
command button. Is there any other way that we can
programmatically
change
the dimensions of the form by clicking on the button. I am a
novice
and
hence
appreciate your cooperation. Also please guide me about how to
remove
the
default menu items from the application.

:

Hi Imran

When you say "minimize", I assume you mean "restore".
"Minimize"
means
reduce it to an icon at the bottom of the screen or on the task
bar,
so
you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not maximized,
 
G

Graham Mandeno

Hi Imran (or if that is your family name, then "Hi Ghani" :)

The controls on a form are always positioned from the top left-hand corner.
This does not change if you maximize the form, so you would expect that
everything will appear to crowd up near the corner when you maximize the
form. This is unavoidable.

If you want to position the contents of the form in the centre then every
control (textbox/label/combo box/etc) will need to be repositioned
individually - not an easy task.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Imran Ghani said:
Hi Mandeno!
Thanks a lot for your very helpful code. The code is indeed working great
when the form is in the Restored state, but when it is maximized again the
contents do not come in the center. Please do guide me for what type of
settings I have to look for. Are there any specific settings I have to
have,
apart from the function call. I am having my call function code in the
form
current code. I'd appreciate your kind help in this regards.

Graham Mandeno said:
Hi Imran

Well, I warned you the code was serious! :)

Copy the code below and paste it into a new, empty module.

Then you can call the function winCenterInMDI from your form code,
passing
the handle of the form's window like this:

Call winCenterInMDI(Me.hWnd)

If the form is already maximized or minimized, then it will be restored,
then it will be centered in the Access window.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

========== start code ===============
Option Compare Text
Option Explicit

Private Const cMaxBuffer = 255

Private Declare Function apiGetClassName _
Lib "user32" _
Alias "GetClassNameA" _
(ByVal hWnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) _
As Long

Private Declare Function apiGetWindow _
Lib "user32" _
Alias "GetWindow" _
(ByVal hWnd As Long, _
ByVal wCmd As Long) _
As Long

Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

Private Declare Function apiShowWindow _
Lib "user32" _
Alias "ShowWindow" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) _
As Long

Private Const SW_RESTORE = 9

Private Declare Function apiIsZoomed _
Lib "user32" _
Alias "IsZoomed" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiIsIconic _
Lib "user32" _
Alias "IsIconic" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiMoveWindow _
Lib "user32" _
Alias "MoveWindow" _
(ByVal hWnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) _
As Long

Private Type winRECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function apiGetWindowRect _
Lib "user32" _
Alias "GetWindowRect" _
(ByVal hWnd As Long, _
lpRect As winRECT) _
As Long

Public Function winGetHWndMDI(Optional hWndApp As Long) As Long
Dim hWnd As Long
winGetHWndMDI = 0
If hWndApp = 0 Then hWndApp = Application.hWndAccessApp
hWnd = apiGetWindow(hWndApp, GW_CHILD)
Do Until hWnd = 0
If winGetClassName(hWnd) = "MDIClient" Then
winGetHWndMDI = hWnd
Exit Do
End If
hWnd = apiGetWindow(hWnd, GW_HWNDNEXT)
Loop
End Function

Public Function winGetClassName(hWnd As Long) As String
Dim sBuffer As String, iLen As Integer
sBuffer = String$(cMaxBuffer - 1, 0)
iLen = apiGetClassName(hWnd, sBuffer, cMaxBuffer)
If iLen > 0 Then
winGetClassName = Left$(sBuffer, iLen)
End If
End Function

Public Function winCenterInMDI(hWnd As Long)
Dim MDIRect As winRECT, WndRect As winRECT
Dim lNewTop As Long, lNewLeft As Long
Dim lHeight As Long, lWidth As Long
' If the form is maximized, restore it.
If apiIsZoomed(hWnd) <> 0 Or apiIsIconic(hWnd) <> 0 Then
apiShowWindow hWnd, SW_RESTORE
End If
' Get the window size of the MDIClient window.
apiGetWindowRect winGetHWndMDI, MDIRect
' Get the window size of the MDIClient window.
apiGetWindowRect hWnd, WndRect
' Calculate Height and Width of window we are moving
With WndRect
lHeight = .Bottom - .Top
lWidth = .Right - .Left
End With
' Calculate new Top and Left coordinates
With MDIRect
lNewTop = (.Bottom - .Top - lHeight) / 2
lNewLeft = (.Right - .Left - lWidth) / 2
End With
' Move the window to the new position
apiMoveWindow hWnd, lNewLeft, lNewTop, lWidth, lHeight, True
End Function
========== end code ===============

Imran Ghani said:
Thanks indeed for your helpful advise. I do want to make my form to
re-center
itself when it is restored. I'd appreciate much your help in this
regards.
Yes, I'd like to code the form for the same purpose. Please go ahead
with
your helpful code for this purpose.

:

Hi Imran

I'm glad you got the Maximize/Restore working :)

If you set the form's AutoCenter property to "Yes" then the form
should
center itself when it is opened. If you then maximize it and
subsequently
restore it, it should revert to its previous position.

However, if you drag it to another location, then maximize/restore it,
it
will stay in that new location.

If you want it to re-center itself when it is restored, then you will
require some much more serious code. Do you really want to go there?
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Thanks for your kind help. Your code worked perfectly with the
form's
maximized and restored positions. Actually the properties set in my
form
were
not allowing the code to work. I have changed the properties and
hence
it
is
all working now. Can you please also guide regarding if I want to
bring
all
the forms' contents in centre of the form when the form is in
restored
position. For the time being the contents of the form are not in the
centre
of the screen when its in restored position.I also want to bring all
the
other forms in my application to the same position, either restored
or
maximized, as the main form. What sort of coding or properties do I
need
to
set to accomplish my goal.

:

Hi Imran

I have not used pictures on command buttons as they are a new
feature
of
Access 2007. However, I believe you should be able to change them
at
run-time simply by assigning another image file name to the Picture
property:

Me.cmdMyButton.Picture = "C:\Icons\NewIcon.ico"

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

message
Thanks for your guidance. Please guide me if we can also change
the
picture
of the command button also indicating the maximize and minimize
position
along with changing the form position. Is there any specific
property
of
the
form which should also be enabled for the form to be maximized or
restored?

:

Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not to
be
working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure, and
see
if
it
works then?

For moving and resizing the form, check out DoCmd.MoveSize
method,
and
also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and
properties
is
the "TWIP". Are TWIP is a "twentieth of a point", which means
there
are
1440 per inch.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


message
Thank you for your valuable help. The caption of the button is
changing,
but
the form is not maximizing or minimizing. I have default menu
bars
on
my
Access 2007 form. I'd be very greatful if you could indicate
about
deficiency
which is not letting me make my form maximize or minimize by
the
use
of
the
command button. Is there any other way that we can
programmatically
change
the dimensions of the form by clicking on the button. I am a
novice
and
hence
appreciate your cooperation. Also please guide me about how to
remove
the
default menu items from the application.

:

Hi Imran

When you say "minimize", I assume you mean "restore".
"Minimize"
means
reduce it to an icon at the bottom of the screen or on the
task
bar,
so
you
wouldn't be able to see the button to maximize it again.

OK, so assuming you open the form in normal view (not
maximized,
 
I

Imran Ghani

Hi Mandeno!
Thanks again for your helpful notes. Please guide me if we can also maximize
or restore the main window of the MS Access with some sort of code or
settings apart from clicking at the top of the window, and also whether we
can change the heading coming at the top of the window, which I think, is
called as Forms MDI window. Can we give a title of ours own at the top? and
further can we remove the windows icons and buttons of all sorts also from
the main window. I being a novice would appreciate much your kind help.

Graham Mandeno said:
Hi Imran (or if that is your family name, then "Hi Ghani" :)

The controls on a form are always positioned from the top left-hand corner.
This does not change if you maximize the form, so you would expect that
everything will appear to crowd up near the corner when you maximize the
form. This is unavoidable.

If you want to position the contents of the form in the centre then every
control (textbox/label/combo box/etc) will need to be repositioned
individually - not an easy task.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Imran Ghani said:
Hi Mandeno!
Thanks a lot for your very helpful code. The code is indeed working great
when the form is in the Restored state, but when it is maximized again the
contents do not come in the center. Please do guide me for what type of
settings I have to look for. Are there any specific settings I have to
have,
apart from the function call. I am having my call function code in the
form
current code. I'd appreciate your kind help in this regards.

Graham Mandeno said:
Hi Imran

Well, I warned you the code was serious! :)

Copy the code below and paste it into a new, empty module.

Then you can call the function winCenterInMDI from your form code,
passing
the handle of the form's window like this:

Call winCenterInMDI(Me.hWnd)

If the form is already maximized or minimized, then it will be restored,
then it will be centered in the Access window.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

========== start code ===============
Option Compare Text
Option Explicit

Private Const cMaxBuffer = 255

Private Declare Function apiGetClassName _
Lib "user32" _
Alias "GetClassNameA" _
(ByVal hWnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) _
As Long

Private Declare Function apiGetWindow _
Lib "user32" _
Alias "GetWindow" _
(ByVal hWnd As Long, _
ByVal wCmd As Long) _
As Long

Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

Private Declare Function apiShowWindow _
Lib "user32" _
Alias "ShowWindow" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) _
As Long

Private Const SW_RESTORE = 9

Private Declare Function apiIsZoomed _
Lib "user32" _
Alias "IsZoomed" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiIsIconic _
Lib "user32" _
Alias "IsIconic" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiMoveWindow _
Lib "user32" _
Alias "MoveWindow" _
(ByVal hWnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) _
As Long

Private Type winRECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function apiGetWindowRect _
Lib "user32" _
Alias "GetWindowRect" _
(ByVal hWnd As Long, _
lpRect As winRECT) _
As Long

Public Function winGetHWndMDI(Optional hWndApp As Long) As Long
Dim hWnd As Long
winGetHWndMDI = 0
If hWndApp = 0 Then hWndApp = Application.hWndAccessApp
hWnd = apiGetWindow(hWndApp, GW_CHILD)
Do Until hWnd = 0
If winGetClassName(hWnd) = "MDIClient" Then
winGetHWndMDI = hWnd
Exit Do
End If
hWnd = apiGetWindow(hWnd, GW_HWNDNEXT)
Loop
End Function

Public Function winGetClassName(hWnd As Long) As String
Dim sBuffer As String, iLen As Integer
sBuffer = String$(cMaxBuffer - 1, 0)
iLen = apiGetClassName(hWnd, sBuffer, cMaxBuffer)
If iLen > 0 Then
winGetClassName = Left$(sBuffer, iLen)
End If
End Function

Public Function winCenterInMDI(hWnd As Long)
Dim MDIRect As winRECT, WndRect As winRECT
Dim lNewTop As Long, lNewLeft As Long
Dim lHeight As Long, lWidth As Long
' If the form is maximized, restore it.
If apiIsZoomed(hWnd) <> 0 Or apiIsIconic(hWnd) <> 0 Then
apiShowWindow hWnd, SW_RESTORE
End If
' Get the window size of the MDIClient window.
apiGetWindowRect winGetHWndMDI, MDIRect
' Get the window size of the MDIClient window.
apiGetWindowRect hWnd, WndRect
' Calculate Height and Width of window we are moving
With WndRect
lHeight = .Bottom - .Top
lWidth = .Right - .Left
End With
' Calculate new Top and Left coordinates
With MDIRect
lNewTop = (.Bottom - .Top - lHeight) / 2
lNewLeft = (.Right - .Left - lWidth) / 2
End With
' Move the window to the new position
apiMoveWindow hWnd, lNewLeft, lNewTop, lWidth, lHeight, True
End Function
========== end code ===============

Thanks indeed for your helpful advise. I do want to make my form to
re-center
itself when it is restored. I'd appreciate much your help in this
regards.
Yes, I'd like to code the form for the same purpose. Please go ahead
with
your helpful code for this purpose.

:

Hi Imran

I'm glad you got the Maximize/Restore working :)

If you set the form's AutoCenter property to "Yes" then the form
should
center itself when it is opened. If you then maximize it and
subsequently
restore it, it should revert to its previous position.

However, if you drag it to another location, then maximize/restore it,
it
will stay in that new location.

If you want it to re-center itself when it is restored, then you will
require some much more serious code. Do you really want to go there?
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


Thanks for your kind help. Your code worked perfectly with the
form's
maximized and restored positions. Actually the properties set in my
form
were
not allowing the code to work. I have changed the properties and
hence
it
is
all working now. Can you please also guide regarding if I want to
bring
all
the forms' contents in centre of the form when the form is in
restored
position. For the time being the contents of the form are not in the
centre
of the screen when its in restored position.I also want to bring all
the
other forms in my application to the same position, either restored
or
maximized, as the main form. What sort of coding or properties do I
need
to
set to accomplish my goal.

:

Hi Imran

I have not used pictures on command buttons as they are a new
feature
of
Access 2007. However, I believe you should be able to change them
at
run-time simply by assigning another image file name to the Picture
property:

Me.cmdMyButton.Picture = "C:\Icons\NewIcon.ico"

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

message
Thanks for your guidance. Please guide me if we can also change
the
picture
of the command button also indicating the maximize and minimize
position
along with changing the form position. Is there any specific
property
of
the
form which should also be enabled for the form to be maximized or
restored?

:

Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not to
be
working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure, and
see
if
it
works then?

For moving and resizing the form, check out DoCmd.MoveSize
method,
and
also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and
properties
is
the "TWIP". Are TWIP is a "twentieth of a point", which means
there
are
1440 per inch.
 
G

Graham Mandeno

Hi Imran

For a novice, you seem to enjoy a good challenge!

To maximize/restore the main Access window, you can use the RunCommand
method:

Application.RunCommand acCmdAppMaximize
Application.RunCommand acCmdAppRestore

To change the window title text of a form, use the form's Caption property.

To change the title text of the main Access window, go to Tools>Startup and
change the "Application Title".

For hiding/showing the system buttons at the top of the main application
window, use the code below...

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


============ start code ==============
Option Explicit

Private Const GWL_STYLE = (-16)

Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000

Private Declare Function apiSetWindowLong _
Lib "user32" _
Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long _
) As Long

Private Declare Function apiGetWindowLong _
Lib "user32" _
Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long _
) As Long

Public Sub ShowAccessSystemButtons(fShow As Boolean)
Dim lStyle As Long
lStyle = apiGetWindowLong(hWndAccessApp, GWL_STYLE)
If fShow Then
lStyle = lStyle Or WS_SYSMENU
Else
lStyle = lStyle And Not WS_SYSMENU
End If
Call apiSetWindowLong(hWndAccessApp, GWL_STYLE, lStyle)
End Sub
============ end code ==============

Imran Ghani said:
Hi Mandeno!
Thanks again for your helpful notes. Please guide me if we can also
maximize
or restore the main window of the MS Access with some sort of code or
settings apart from clicking at the top of the window, and also whether we
can change the heading coming at the top of the window, which I think, is
called as Forms MDI window. Can we give a title of ours own at the top?
and
further can we remove the windows icons and buttons of all sorts also from
the main window. I being a novice would appreciate much your kind help.

Graham Mandeno said:
Hi Imran (or if that is your family name, then "Hi Ghani" :)

The controls on a form are always positioned from the top left-hand
corner.
This does not change if you maximize the form, so you would expect that
everything will appear to crowd up near the corner when you maximize the
form. This is unavoidable.

If you want to position the contents of the form in the centre then every
control (textbox/label/combo box/etc) will need to be repositioned
individually - not an easy task.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Imran Ghani said:
Hi Mandeno!
Thanks a lot for your very helpful code. The code is indeed working
great
when the form is in the Restored state, but when it is maximized again
the
contents do not come in the center. Please do guide me for what type of
settings I have to look for. Are there any specific settings I have to
have,
apart from the function call. I am having my call function code in the
form
current code. I'd appreciate your kind help in this regards.

:

Hi Imran

Well, I warned you the code was serious! :)

Copy the code below and paste it into a new, empty module.

Then you can call the function winCenterInMDI from your form code,
passing
the handle of the form's window like this:

Call winCenterInMDI(Me.hWnd)

If the form is already maximized or minimized, then it will be
restored,
then it will be centered in the Access window.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

========== start code ===============
Option Compare Text
Option Explicit

Private Const cMaxBuffer = 255

Private Declare Function apiGetClassName _
Lib "user32" _
Alias "GetClassNameA" _
(ByVal hWnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) _
As Long

Private Declare Function apiGetWindow _
Lib "user32" _
Alias "GetWindow" _
(ByVal hWnd As Long, _
ByVal wCmd As Long) _
As Long

Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

Private Declare Function apiShowWindow _
Lib "user32" _
Alias "ShowWindow" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) _
As Long

Private Const SW_RESTORE = 9

Private Declare Function apiIsZoomed _
Lib "user32" _
Alias "IsZoomed" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiIsIconic _
Lib "user32" _
Alias "IsIconic" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiMoveWindow _
Lib "user32" _
Alias "MoveWindow" _
(ByVal hWnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) _
As Long

Private Type winRECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function apiGetWindowRect _
Lib "user32" _
Alias "GetWindowRect" _
(ByVal hWnd As Long, _
lpRect As winRECT) _
As Long

Public Function winGetHWndMDI(Optional hWndApp As Long) As Long
Dim hWnd As Long
winGetHWndMDI = 0
If hWndApp = 0 Then hWndApp = Application.hWndAccessApp
hWnd = apiGetWindow(hWndApp, GW_CHILD)
Do Until hWnd = 0
If winGetClassName(hWnd) = "MDIClient" Then
winGetHWndMDI = hWnd
Exit Do
End If
hWnd = apiGetWindow(hWnd, GW_HWNDNEXT)
Loop
End Function

Public Function winGetClassName(hWnd As Long) As String
Dim sBuffer As String, iLen As Integer
sBuffer = String$(cMaxBuffer - 1, 0)
iLen = apiGetClassName(hWnd, sBuffer, cMaxBuffer)
If iLen > 0 Then
winGetClassName = Left$(sBuffer, iLen)
End If
End Function

Public Function winCenterInMDI(hWnd As Long)
Dim MDIRect As winRECT, WndRect As winRECT
Dim lNewTop As Long, lNewLeft As Long
Dim lHeight As Long, lWidth As Long
' If the form is maximized, restore it.
If apiIsZoomed(hWnd) <> 0 Or apiIsIconic(hWnd) <> 0 Then
apiShowWindow hWnd, SW_RESTORE
End If
' Get the window size of the MDIClient window.
apiGetWindowRect winGetHWndMDI, MDIRect
' Get the window size of the MDIClient window.
apiGetWindowRect hWnd, WndRect
' Calculate Height and Width of window we are moving
With WndRect
lHeight = .Bottom - .Top
lWidth = .Right - .Left
End With
' Calculate new Top and Left coordinates
With MDIRect
lNewTop = (.Bottom - .Top - lHeight) / 2
lNewLeft = (.Right - .Left - lWidth) / 2
End With
' Move the window to the new position
apiMoveWindow hWnd, lNewLeft, lNewTop, lWidth, lHeight, True
End Function
========== end code ===============

Thanks indeed for your helpful advise. I do want to make my form to
re-center
itself when it is restored. I'd appreciate much your help in this
regards.
Yes, I'd like to code the form for the same purpose. Please go ahead
with
your helpful code for this purpose.

:

Hi Imran

I'm glad you got the Maximize/Restore working :)

If you set the form's AutoCenter property to "Yes" then the form
should
center itself when it is opened. If you then maximize it and
subsequently
restore it, it should revert to its previous position.

However, if you drag it to another location, then maximize/restore
it,
it
will stay in that new location.

If you want it to re-center itself when it is restored, then you
will
require some much more serious code. Do you really want to go
there?
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


message
Thanks for your kind help. Your code worked perfectly with the
form's
maximized and restored positions. Actually the properties set in
my
form
were
not allowing the code to work. I have changed the properties and
hence
it
is
all working now. Can you please also guide regarding if I want to
bring
all
the forms' contents in centre of the form when the form is in
restored
position. For the time being the contents of the form are not in
the
centre
of the screen when its in restored position.I also want to bring
all
the
other forms in my application to the same position, either
restored
or
maximized, as the main form. What sort of coding or properties do
I
need
to
set to accomplish my goal.

:

Hi Imran

I have not used pictures on command buttons as they are a new
feature
of
Access 2007. However, I believe you should be able to change
them
at
run-time simply by assigning another image file name to the
Picture
property:

Me.cmdMyButton.Picture = "C:\Icons\NewIcon.ico"

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

message
Thanks for your guidance. Please guide me if we can also
change
the
picture
of the command button also indicating the maximize and
minimize
position
along with changing the form position. Is there any specific
property
of
the
form which should also be enabled for the form to be maximized
or
restored?

:

Hi Imran

I'm sorry, I can't think of a reason for DoCmd.Maximize not
to
be
working.

Can you try creating a new form with nothing on it except the
cmdToggleMaximize command button, and the event procedure,
and
see
if
it
works then?

For moving and resizing the form, check out DoCmd.MoveSize
method,
and
also
the form's InsideHeight and InsideWidth properties.

You should be aware that the units for all these methods and
properties
is
the "TWIP". Are TWIP is a "twentieth of a point", which
means
there
are
1440 per inch.
 
I

Imran Ghani

Hi Mandeno

Thanks a lot indeed for your very helpful code. My Application window is
maximizing and minimizing perfectly. I'd like to appreciate for the valuable
time which you are sharing with me. Please advise me where to put the code
for hiding/showing the system buttons at the top of the main application
window for it to work. Please also guide me where to find the tools and
startup options in Access 2007. Thanks again.

Graham Mandeno said:
Hi Imran

For a novice, you seem to enjoy a good challenge!

To maximize/restore the main Access window, you can use the RunCommand
method:

Application.RunCommand acCmdAppMaximize
Application.RunCommand acCmdAppRestore

To change the window title text of a form, use the form's Caption property.

To change the title text of the main Access window, go to Tools>Startup and
change the "Application Title".

For hiding/showing the system buttons at the top of the main application
window, use the code below...

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


============ start code ==============
Option Explicit

Private Const GWL_STYLE = (-16)

Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000

Private Declare Function apiSetWindowLong _
Lib "user32" _
Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long _
) As Long

Private Declare Function apiGetWindowLong _
Lib "user32" _
Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long _
) As Long

Public Sub ShowAccessSystemButtons(fShow As Boolean)
Dim lStyle As Long
lStyle = apiGetWindowLong(hWndAccessApp, GWL_STYLE)
If fShow Then
lStyle = lStyle Or WS_SYSMENU
Else
lStyle = lStyle And Not WS_SYSMENU
End If
Call apiSetWindowLong(hWndAccessApp, GWL_STYLE, lStyle)
End Sub
============ end code ==============

Imran Ghani said:
Hi Mandeno!
Thanks again for your helpful notes. Please guide me if we can also
maximize
or restore the main window of the MS Access with some sort of code or
settings apart from clicking at the top of the window, and also whether we
can change the heading coming at the top of the window, which I think, is
called as Forms MDI window. Can we give a title of ours own at the top?
and
further can we remove the windows icons and buttons of all sorts also from
the main window. I being a novice would appreciate much your kind help.

Graham Mandeno said:
Hi Imran (or if that is your family name, then "Hi Ghani" :)

The controls on a form are always positioned from the top left-hand
corner.
This does not change if you maximize the form, so you would expect that
everything will appear to crowd up near the corner when you maximize the
form. This is unavoidable.

If you want to position the contents of the form in the centre then every
control (textbox/label/combo box/etc) will need to be repositioned
individually - not an easy task.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi Mandeno!
Thanks a lot for your very helpful code. The code is indeed working
great
when the form is in the Restored state, but when it is maximized again
the
contents do not come in the center. Please do guide me for what type of
settings I have to look for. Are there any specific settings I have to
have,
apart from the function call. I am having my call function code in the
form
current code. I'd appreciate your kind help in this regards.

:

Hi Imran

Well, I warned you the code was serious! :)

Copy the code below and paste it into a new, empty module.

Then you can call the function winCenterInMDI from your form code,
passing
the handle of the form's window like this:

Call winCenterInMDI(Me.hWnd)

If the form is already maximized or minimized, then it will be
restored,
then it will be centered in the Access window.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

========== start code ===============
Option Compare Text
Option Explicit

Private Const cMaxBuffer = 255

Private Declare Function apiGetClassName _
Lib "user32" _
Alias "GetClassNameA" _
(ByVal hWnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) _
As Long

Private Declare Function apiGetWindow _
Lib "user32" _
Alias "GetWindow" _
(ByVal hWnd As Long, _
ByVal wCmd As Long) _
As Long

Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

Private Declare Function apiShowWindow _
Lib "user32" _
Alias "ShowWindow" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) _
As Long

Private Const SW_RESTORE = 9

Private Declare Function apiIsZoomed _
Lib "user32" _
Alias "IsZoomed" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiIsIconic _
Lib "user32" _
Alias "IsIconic" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiMoveWindow _
Lib "user32" _
Alias "MoveWindow" _
(ByVal hWnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) _
As Long

Private Type winRECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function apiGetWindowRect _
Lib "user32" _
Alias "GetWindowRect" _
(ByVal hWnd As Long, _
lpRect As winRECT) _
As Long

Public Function winGetHWndMDI(Optional hWndApp As Long) As Long
Dim hWnd As Long
winGetHWndMDI = 0
If hWndApp = 0 Then hWndApp = Application.hWndAccessApp
hWnd = apiGetWindow(hWndApp, GW_CHILD)
Do Until hWnd = 0
If winGetClassName(hWnd) = "MDIClient" Then
winGetHWndMDI = hWnd
Exit Do
End If
hWnd = apiGetWindow(hWnd, GW_HWNDNEXT)
Loop
End Function

Public Function winGetClassName(hWnd As Long) As String
Dim sBuffer As String, iLen As Integer
sBuffer = String$(cMaxBuffer - 1, 0)
iLen = apiGetClassName(hWnd, sBuffer, cMaxBuffer)
If iLen > 0 Then
winGetClassName = Left$(sBuffer, iLen)
End If
End Function

Public Function winCenterInMDI(hWnd As Long)
Dim MDIRect As winRECT, WndRect As winRECT
Dim lNewTop As Long, lNewLeft As Long
Dim lHeight As Long, lWidth As Long
' If the form is maximized, restore it.
If apiIsZoomed(hWnd) <> 0 Or apiIsIconic(hWnd) <> 0 Then
apiShowWindow hWnd, SW_RESTORE
End If
' Get the window size of the MDIClient window.
apiGetWindowRect winGetHWndMDI, MDIRect
' Get the window size of the MDIClient window.
apiGetWindowRect hWnd, WndRect
' Calculate Height and Width of window we are moving
With WndRect
lHeight = .Bottom - .Top
lWidth = .Right - .Left
End With
' Calculate new Top and Left coordinates
With MDIRect
lNewTop = (.Bottom - .Top - lHeight) / 2
lNewLeft = (.Right - .Left - lWidth) / 2
End With
' Move the window to the new position
apiMoveWindow hWnd, lNewLeft, lNewTop, lWidth, lHeight, True
End Function
========== end code ===============

Thanks indeed for your helpful advise. I do want to make my form to
re-center
itself when it is restored. I'd appreciate much your help in this
regards.
Yes, I'd like to code the form for the same purpose. Please go ahead
with
your helpful code for this purpose.

:

Hi Imran

I'm glad you got the Maximize/Restore working :)

If you set the form's AutoCenter property to "Yes" then the form
should
center itself when it is opened. If you then maximize it and
subsequently
restore it, it should revert to its previous position.

However, if you drag it to another location, then maximize/restore
it,
it
will stay in that new location.

If you want it to re-center itself when it is restored, then you
will
require some much more serious code. Do you really want to go
there?
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


message
Thanks for your kind help. Your code worked perfectly with the
form's
maximized and restored positions. Actually the properties set in
my
form
were
not allowing the code to work. I have changed the properties and
 
G

Graham Mandeno

Hi Imran

[you can call me "Graham" --- "Mandeno" is my family name :) ]

To hide the system buttons:
Call ShowAccessSystemButtons( False )

and to show them again:
Call ShowAccessSystemButtons( True )

Sorry, Tools > Startup in for Access 97-2003.

For Access 2007:

1. Click the round "pizza" button at the top left.

2. Click "Access Options" near bottom right.

3. Click "Current Database" in the list on the left.

You will see "Application Title" (and other things you can experiment with)
on that screen.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Imran Ghani said:
Hi Mandeno

Thanks a lot indeed for your very helpful code. My Application window is
maximizing and minimizing perfectly. I'd like to appreciate for the
valuable
time which you are sharing with me. Please advise me where to put the code
for hiding/showing the system buttons at the top of the main application
window for it to work. Please also guide me where to find the tools and
startup options in Access 2007. Thanks again.

Graham Mandeno said:
Hi Imran

For a novice, you seem to enjoy a good challenge!

To maximize/restore the main Access window, you can use the RunCommand
method:

Application.RunCommand acCmdAppMaximize
Application.RunCommand acCmdAppRestore

To change the window title text of a form, use the form's Caption
property.

To change the title text of the main Access window, go to Tools>Startup
and
change the "Application Title".

For hiding/showing the system buttons at the top of the main application
window, use the code below...

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


============ start code ==============
Option Explicit

Private Const GWL_STYLE = (-16)

Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000

Private Declare Function apiSetWindowLong _
Lib "user32" _
Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long _
) As Long

Private Declare Function apiGetWindowLong _
Lib "user32" _
Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long _
) As Long

Public Sub ShowAccessSystemButtons(fShow As Boolean)
Dim lStyle As Long
lStyle = apiGetWindowLong(hWndAccessApp, GWL_STYLE)
If fShow Then
lStyle = lStyle Or WS_SYSMENU
Else
lStyle = lStyle And Not WS_SYSMENU
End If
Call apiSetWindowLong(hWndAccessApp, GWL_STYLE, lStyle)
End Sub
============ end code ==============

Imran Ghani said:
Hi Mandeno!
Thanks again for your helpful notes. Please guide me if we can also
maximize
or restore the main window of the MS Access with some sort of code or
settings apart from clicking at the top of the window, and also whether
we
can change the heading coming at the top of the window, which I think,
is
called as Forms MDI window. Can we give a title of ours own at the top?
and
further can we remove the windows icons and buttons of all sorts also
from
the main window. I being a novice would appreciate much your kind help.

:

Hi Imran (or if that is your family name, then "Hi Ghani" :)

The controls on a form are always positioned from the top left-hand
corner.
This does not change if you maximize the form, so you would expect
that
everything will appear to crowd up near the corner when you maximize
the
form. This is unavoidable.

If you want to position the contents of the form in the centre then
every
control (textbox/label/combo box/etc) will need to be repositioned
individually - not an easy task.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi Mandeno!
Thanks a lot for your very helpful code. The code is indeed working
great
when the form is in the Restored state, but when it is maximized
again
the
contents do not come in the center. Please do guide me for what type
of
settings I have to look for. Are there any specific settings I have
to
have,
apart from the function call. I am having my call function code in
the
form
current code. I'd appreciate your kind help in this regards.

:

Hi Imran

Well, I warned you the code was serious! :)

Copy the code below and paste it into a new, empty module.

Then you can call the function winCenterInMDI from your form code,
passing
the handle of the form's window like this:

Call winCenterInMDI(Me.hWnd)

If the form is already maximized or minimized, then it will be
restored,
then it will be centered in the Access window.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

========== start code ===============
Option Compare Text
Option Explicit

Private Const cMaxBuffer = 255

Private Declare Function apiGetClassName _
Lib "user32" _
Alias "GetClassNameA" _
(ByVal hWnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) _
As Long

Private Declare Function apiGetWindow _
Lib "user32" _
Alias "GetWindow" _
(ByVal hWnd As Long, _
ByVal wCmd As Long) _
As Long

Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

Private Declare Function apiShowWindow _
Lib "user32" _
Alias "ShowWindow" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) _
As Long

Private Const SW_RESTORE = 9

Private Declare Function apiIsZoomed _
Lib "user32" _
Alias "IsZoomed" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiIsIconic _
Lib "user32" _
Alias "IsIconic" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiMoveWindow _
Lib "user32" _
Alias "MoveWindow" _
(ByVal hWnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) _
As Long

Private Type winRECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function apiGetWindowRect _
Lib "user32" _
Alias "GetWindowRect" _
(ByVal hWnd As Long, _
lpRect As winRECT) _
As Long

Public Function winGetHWndMDI(Optional hWndApp As Long) As Long
Dim hWnd As Long
winGetHWndMDI = 0
If hWndApp = 0 Then hWndApp = Application.hWndAccessApp
hWnd = apiGetWindow(hWndApp, GW_CHILD)
Do Until hWnd = 0
If winGetClassName(hWnd) = "MDIClient" Then
winGetHWndMDI = hWnd
Exit Do
End If
hWnd = apiGetWindow(hWnd, GW_HWNDNEXT)
Loop
End Function

Public Function winGetClassName(hWnd As Long) As String
Dim sBuffer As String, iLen As Integer
sBuffer = String$(cMaxBuffer - 1, 0)
iLen = apiGetClassName(hWnd, sBuffer, cMaxBuffer)
If iLen > 0 Then
winGetClassName = Left$(sBuffer, iLen)
End If
End Function

Public Function winCenterInMDI(hWnd As Long)
Dim MDIRect As winRECT, WndRect As winRECT
Dim lNewTop As Long, lNewLeft As Long
Dim lHeight As Long, lWidth As Long
' If the form is maximized, restore it.
If apiIsZoomed(hWnd) <> 0 Or apiIsIconic(hWnd) <> 0 Then
apiShowWindow hWnd, SW_RESTORE
End If
' Get the window size of the MDIClient window.
apiGetWindowRect winGetHWndMDI, MDIRect
' Get the window size of the MDIClient window.
apiGetWindowRect hWnd, WndRect
' Calculate Height and Width of window we are moving
With WndRect
lHeight = .Bottom - .Top
lWidth = .Right - .Left
End With
' Calculate new Top and Left coordinates
With MDIRect
lNewTop = (.Bottom - .Top - lHeight) / 2
lNewLeft = (.Right - .Left - lWidth) / 2
End With
' Move the window to the new position
apiMoveWindow hWnd, lNewLeft, lNewTop, lWidth, lHeight, True
End Function
========== end code ===============

message
Thanks indeed for your helpful advise. I do want to make my form
to
re-center
itself when it is restored. I'd appreciate much your help in this
regards.
Yes, I'd like to code the form for the same purpose. Please go
ahead
with
your helpful code for this purpose.

:

Hi Imran

I'm glad you got the Maximize/Restore working :)

If you set the form's AutoCenter property to "Yes" then the form
should
center itself when it is opened. If you then maximize it and
subsequently
restore it, it should revert to its previous position.

However, if you drag it to another location, then
maximize/restore
it,
it
will stay in that new location.

If you want it to re-center itself when it is restored, then you
will
require some much more serious code. Do you really want to go
there?
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


message
Thanks for your kind help. Your code worked perfectly with the
form's
maximized and restored positions. Actually the properties set
in
my
form
were
not allowing the code to work. I have changed the properties
and
 
I

Imran Ghani

Hi Graham (Apologies for the previous mistake and thanks for correction)
I do appreciate much your great help. I am able to change my application
title of the main window. I have applied the Call ShowAccessSystemButtons(
False ) on the form and a button also for hiding/showing the system buttons
at the top of the main application but upto now with no success. Please do
guide in this respect where should I put my code for it to get working.


Graham Mandeno said:
Hi Imran

[you can call me "Graham" --- "Mandeno" is my family name :) ]

To hide the system buttons:
Call ShowAccessSystemButtons( False )

and to show them again:
Call ShowAccessSystemButtons( True )

Sorry, Tools > Startup in for Access 97-2003.

For Access 2007:

1. Click the round "pizza" button at the top left.

2. Click "Access Options" near bottom right.

3. Click "Current Database" in the list on the left.

You will see "Application Title" (and other things you can experiment with)
on that screen.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Imran Ghani said:
Hi Mandeno

Thanks a lot indeed for your very helpful code. My Application window is
maximizing and minimizing perfectly. I'd like to appreciate for the
valuable
time which you are sharing with me. Please advise me where to put the code
for hiding/showing the system buttons at the top of the main application
window for it to work. Please also guide me where to find the tools and
startup options in Access 2007. Thanks again.

Graham Mandeno said:
Hi Imran

For a novice, you seem to enjoy a good challenge!

To maximize/restore the main Access window, you can use the RunCommand
method:

Application.RunCommand acCmdAppMaximize
Application.RunCommand acCmdAppRestore

To change the window title text of a form, use the form's Caption
property.

To change the title text of the main Access window, go to Tools>Startup
and
change the "Application Title".

For hiding/showing the system buttons at the top of the main application
window, use the code below...

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


============ start code ==============
Option Explicit

Private Const GWL_STYLE = (-16)

Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000

Private Declare Function apiSetWindowLong _
Lib "user32" _
Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long _
) As Long

Private Declare Function apiGetWindowLong _
Lib "user32" _
Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long _
) As Long

Public Sub ShowAccessSystemButtons(fShow As Boolean)
Dim lStyle As Long
lStyle = apiGetWindowLong(hWndAccessApp, GWL_STYLE)
If fShow Then
lStyle = lStyle Or WS_SYSMENU
Else
lStyle = lStyle And Not WS_SYSMENU
End If
Call apiSetWindowLong(hWndAccessApp, GWL_STYLE, lStyle)
End Sub
============ end code ==============

Hi Mandeno!
Thanks again for your helpful notes. Please guide me if we can also
maximize
or restore the main window of the MS Access with some sort of code or
settings apart from clicking at the top of the window, and also whether
we
can change the heading coming at the top of the window, which I think,
is
called as Forms MDI window. Can we give a title of ours own at the top?
and
further can we remove the windows icons and buttons of all sorts also
from
the main window. I being a novice would appreciate much your kind help.

:

Hi Imran (or if that is your family name, then "Hi Ghani" :)

The controls on a form are always positioned from the top left-hand
corner.
This does not change if you maximize the form, so you would expect
that
everything will appear to crowd up near the corner when you maximize
the
form. This is unavoidable.

If you want to position the contents of the form in the centre then
every
control (textbox/label/combo box/etc) will need to be repositioned
individually - not an easy task.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Hi Mandeno!
Thanks a lot for your very helpful code. The code is indeed working
great
when the form is in the Restored state, but when it is maximized
again
the
contents do not come in the center. Please do guide me for what type
of
settings I have to look for. Are there any specific settings I have
to
have,
apart from the function call. I am having my call function code in
the
form
current code. I'd appreciate your kind help in this regards.

:

Hi Imran

Well, I warned you the code was serious! :)

Copy the code below and paste it into a new, empty module.

Then you can call the function winCenterInMDI from your form code,
passing
the handle of the form's window like this:

Call winCenterInMDI(Me.hWnd)

If the form is already maximized or minimized, then it will be
restored,
then it will be centered in the Access window.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

========== start code ===============
Option Compare Text
Option Explicit

Private Const cMaxBuffer = 255

Private Declare Function apiGetClassName _
Lib "user32" _
Alias "GetClassNameA" _
(ByVal hWnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) _
As Long

Private Declare Function apiGetWindow _
Lib "user32" _
Alias "GetWindow" _
(ByVal hWnd As Long, _
ByVal wCmd As Long) _
As Long

Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

Private Declare Function apiShowWindow _
Lib "user32" _
Alias "ShowWindow" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) _
As Long

Private Const SW_RESTORE = 9

Private Declare Function apiIsZoomed _
Lib "user32" _
Alias "IsZoomed" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiIsIconic _
Lib "user32" _
Alias "IsIconic" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiMoveWindow _
Lib "user32" _
Alias "MoveWindow" _
(ByVal hWnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) _
As Long

Private Type winRECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function apiGetWindowRect _
Lib "user32" _
Alias "GetWindowRect" _
(ByVal hWnd As Long, _
lpRect As winRECT) _
As Long

Public Function winGetHWndMDI(Optional hWndApp As Long) As Long
Dim hWnd As Long
winGetHWndMDI = 0
If hWndApp = 0 Then hWndApp = Application.hWndAccessApp
hWnd = apiGetWindow(hWndApp, GW_CHILD)
Do Until hWnd = 0
If winGetClassName(hWnd) = "MDIClient" Then
winGetHWndMDI = hWnd
Exit Do
End If
hWnd = apiGetWindow(hWnd, GW_HWNDNEXT)
Loop
End Function

Public Function winGetClassName(hWnd As Long) As String
Dim sBuffer As String, iLen As Integer
sBuffer = String$(cMaxBuffer - 1, 0)
iLen = apiGetClassName(hWnd, sBuffer, cMaxBuffer)
If iLen > 0 Then
winGetClassName = Left$(sBuffer, iLen)
End If
End Function

Public Function winCenterInMDI(hWnd As Long)
Dim MDIRect As winRECT, WndRect As winRECT
Dim lNewTop As Long, lNewLeft As Long
Dim lHeight As Long, lWidth As Long
' If the form is maximized, restore it.
If apiIsZoomed(hWnd) <> 0 Or apiIsIconic(hWnd) <> 0 Then
apiShowWindow hWnd, SW_RESTORE
End If
' Get the window size of the MDIClient window.
apiGetWindowRect winGetHWndMDI, MDIRect
' Get the window size of the MDIClient window.
apiGetWindowRect hWnd, WndRect
' Calculate Height and Width of window we are moving
With WndRect
lHeight = .Bottom - .Top
lWidth = .Right - .Left
End With
' Calculate new Top and Left coordinates
With MDIRect
lNewTop = (.Bottom - .Top - lHeight) / 2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top