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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Minimizing a database 2

Status
Not open for further replies.

rebel4k

IS-IT--Management
Apr 18, 2002
80
GB
I have just created a an access database. I have included a minimize button on all of the forms. This works fine, however when I click the button, it only minimizes the form, and the access window appears in the background. Is there any way that I can get this button to minimize the whole database and not just the form. Any help would be most appreciated.

Thanks
 
Try this in the On_click event of the button:

Code:
Private Sub btnMinimise_Click()
    SendKeys ("% n"), True
End Sub

This uses the SendKeys function to mimic the user pressing the keys:

[Alt] + [Spacebar]
[Alt] + n

which minimises the application window.


Bob Stubbs
 
Try this in the On_click event of the button:

Code:
Private Sub btnMinimise_Click()
    SendKeys ("% n"), True
End Sub

This uses the SendKeys function to mimic the user pressing the keys:

[Alt] + [Spacebar] followed by n

... which minimises the application window.





Bob Stubbs
 
BobStubbs, that's pretty cool. Do you know of a good reference for using the SendKeys method - I mean, of different things that can be done, such as a close button, or a next/previous record button, etc? I like that for sure - fast and simple.
Have a star!

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
I'm glad this worked for you. I find SendKeys useful in many places where you need a simple way to mimic actual keystrokes.

I don't know of a specific source of information on SendKeys, but I suggest you should look in a programming guide for 'pure' Visual Basic, rather than VBA. I learned functions like SendKeys while writing small applications in Visual Basic for my company.

The Visual Basic help file topic 'SendKeys' is quite useful - you can find this in Access 2000 VBA help, for example.


Bob Stubbs
 
Sorry my earlier post ended half way through ... PC problems! Here are a few examples of SendKeys from my own databases, which may give you some useful ideas.

Tool bar button which types today's date into a field
Put this code into a module, and assign it to a tool bar button (or a button on a form if you prefer):
Code:
Public Function TypeDate()

'----------------------------------------------
'- Uses SendKeys to type today's date, in     -
'- dd/mm/yyyy format, into a database field.  -
'- Associated with a toolbar button.          -
'----------------------------------------------

Dim strToday As String

    strToday = Format$(Now, "dd/mm/yyyy") & " "
    SendKeys strToday, True

End Function
Change the date format as required, and remove the following space if you don't need it.
______________________________________________

One line of code, to position the cursor at the start of a field when you click into the field with the mouse:
Code:
Private Sub MyFieldName_Click()
    SendKeys ("{Home}")
End Sub
______________________________________________

Modification to the standard code which the Access wizard generates behind a button on a form, which opens another form and displays a related record:
Code:
Private Sub btnOpenAppUseForm_Click()
On Error GoTo Err_btnOpenAppUseForm_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmApplicationUse"
    
    stLinkCriteria = "[EmployeeID]=" & Me![EmployeeID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    SendKeys (Me![EmployeeListName]), True
    SendKeys (Chr$(9)), True

Exit_btnOpenAppUseForm_Click:
    Exit Sub

Err_btnOpenAppUseForm_Click:
    MsgBox Err.Description
    Resume Exit_btnOpenAppUseForm_Click
    
End Sub
In my form frmApplicationUse, I have two unbound combo boxes, used to select a record to view. The Sendkeys code which I have added:
-- Sends the contents of the field 'EmployeeListName' from the original form into the first combo box on thje second form.
-- Tabs to the second combo box
(I then have some code in the second combo box which makes it drop down when you tab into it)
The result is that when the user clicks the button in the first form, the nsecond form is pre-filled with the correct name, and a list of records associated with that person drops down on screen.
______________________________________________

Another simple one ... set the focus to a combo box, then type the contents of a variable, set earlier, into it:
Code:
    cmbEmployeeName.SetFocus
    SendKeys (strPreviousName)
This lets you remember a value at one point in your code, then type it back somewhere else later.
______________________________________________

I hope that these examples will give you a few ideas to get you started - note that you can send:
-- Literal text
-- Keystrokes
-- contents of a string variable
... which makes SendKeys quite versatile!

Kind regards,


Bob Stubbs
 
That all looks pretty cool! Thanks a ton - the date thing I find very helpful, and I recorded a macro to do something similar in Excel, but not for Access yet. I'll probably use at least some of these ideas, and definitely intend on looking in more detail at the SendKeys method. I'd post a 2nd star myself, but can't b/c of the site settings on that - which I guess is a good thing in most cases. [wink]

Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
Nice code. It works well, but I choose to let my form window have Modal & popup ON & I've disable the minimize & close buttons in an effort to prevent the user from gaining access to the DB tables & queries (security).

any advise how to minimize with popup/modal on?
 
DoCmd.RunCommand acCmdAppMaximize
DoCmd.RunCommand acCmdAppMinimize


Herman

They say that crime doesn't pay... does that mean my job is a crime?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top