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

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

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

Controlling the look of Access using magical powers??

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
0
0
GB
I have macros in a database which open certain forms. How would I force the whole of Access' window to be just big enough to fit the form that has been opened in? The only problem is that each macro opens a form of a different size.

Would I have to convert the code to a module, and from there are there lots of VB commands that will control the layout of the whole of Access such as removing toolbars and resizing etc. to simplify the view?

Any help or suggestions to do this would be very helpful.

Thanks

elziko
 
Some toolbars can be controlled in the 'startup' properties of the database. This is found in the tools menu. Other buttons are set using the properties of the form, i.e. minimize, close. You can have a form open to a certain size by opening the form in design view, resizing the window that the form is opened in, then saving the form.

Mike Rohde
rohdem@marshallengines.com
 
If I'm understanding you correctly, you are having Macros pull up different sized Forms but they're not resizing themselves to the data displayed in the forms... The answer to this query is to make sure that the borders are set where you want them in the Form Design, open the Form Properties, select the Format tab, and in "Auto Resize", double-click to select "Yes"... Also valuable is the "Auto Center" feature where, if selected as "Yes", will center the form on the screen of any particular user, regardless of their screen size...

BanditLV
Las Vegas
 
Thanks and sorry, I didn't make myself very clear. My forms are fine. I want the WHOLE Access window to be cut down (minimal menus/toolbars) and only just big enough to surround the current form. It does remember its size but then when I open another database with a different sized form it doesn't fit properly. I need some sort of contol over the Whole Access aplication window in VB or macros.

Anyone know if this is possible??

elziko
 
Add a new module with the following pasted into it!

Option Compare Database
Option Explicit
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3


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

Function fSetAccessWindow(nCmdShow As Long)
'Usage Examples
'Maximize window:
' ?fSetAccessWindow(3)
'Minimize window:
' ?fSetAccessWindow(2)
'Hide window:
' ?fSetAccessWindow(0)
'Normal window:
' ?fSetAccessWindow(1)
'
Dim loX As Long
Dim loForm As Form
On Error Resume Next
Set loForm = Screen.ActiveForm
If err <> 0 Then 'no Activeform
If nCmdShow = SW_HIDE Then
MsgBox &quot;Cannot hide Access unless &quot; _
& &quot;a form is on screen&quot;
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
err.Clear
End If
Else
If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
MsgBox &quot;Cannot minimize Access with &quot; _
& (loForm.Caption + &quot; &quot;) _
& &quot;form on screen&quot;
ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Then
MsgBox &quot;Cannot hide Access with &quot; _
& (loForm.Caption + &quot; &quot;) _
& &quot;form on screen&quot;
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
End If
End If
fSetAccessWindow = (loX <> 0)
End Function

You will then need to call the function as fSetAccessWindow(0) to hide the Access Window and then call fSetAccessWindow(3) to restore the window (you must restore the window at the end or the next time you open Access you will have problems)

These are called on the 'OnOpen' part of your form.

Hope it helps!

Jon
 
This might get you headed in the right direction.
Create a new module and add these Declarations

Declare Function GetWindowRect Lib &quot;user32.dll&quot; (ByVal hwnd As Long, _
lpRect As RECT) As Long
Declare Function MoveWindow Lib &quot;user32.dll&quot; (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

Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type

Then in the Each Form's Load Event add this:

Dim rForm As RECT
Dim retval As Long ' return value
Dim lngHeight As Long, lngWidth As Long
retval = GetWindowRect(Me.hwnd, rForm) ' set r equal to Form1's rectangle
lngWidth = rForm.right - rForm.left
lngWidth = lngWidth + 50
lngHeight = rForm.bottom - rForm.top
lngHeight = lngHeight + 100
retval = MoveWindow(Application.hWndAccessApp, 1, 1, lngWidth, lngHeight, 1)
retval = MoveWindow(Me.hwnd, 0, 0, lngWidth - 50, lngHeight - 100, 1)


HTH
PaulF
 
Thanks both of you. I've decided to go with Paul on this one cos it looks simpler and today my mind is small.

PaulF,

I got it working but as you probably know it leaves a border around the form. I've tried leaving out the lines which add a bit onto lngWidth and lngHeight but this makes the window &quot;eat into&quot; the form.

Do you know how to get it spot on? But thanks anyway cos I'm doing a whole lot better already!

elziko
 
not really, the code I provided to you was based on trial and error. The data was what I ended up with to allow the entire form to appear inside the Access window based on the settings of my PC. I guess you'll just have to mess with it to get it to appear exactly as you want it to. Sorry; but to be honest with you, I didn't have a clue how to do this, until I started messing with different Properties and API Calls. BTW you can get additional information on the API Calls (and others) at:
PaulF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top