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

Can I tell by what method a form was opened? 1

Status
Not open for further replies.

wemeier

IS-IT--Management
Aug 15, 2001
324
US
In Tools | Startup on my database I specify a form name in the "Display Form" control. This, of course, opens that form when the database is opened without holding down the Shift key.

I have some coding that I want to bypass if I open the form from the Database Window while I'm working on the database. Is there any way to identify that a form was opened as part of the Startup options as opposed to being opened from the Database Window?

Likewise, can I tell if a form is opened from VBA code in an Event Procedure (other than setting OpenArgs or something) as opposed to being opened from the Database Window?


[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
Don't know, but an easy workaround, would be to use the AutoExec macro to both call the code you wish to run and open the form. Then the code wouldn't run, if the form is opened from the database window.

I think the OpenArgs is probably best way to determine how it is opened (unless you don't show your users the database window at all;-))

Roy-Vidar
 
Yeah, I thought of that. I was hoping for a better way so I can use it for other situations and not just at Startup. Thanks!

By the way, if I set an Application Title in Startup, can I interrogate that somewhere? That may be another way to do it as the application title does not display when you bypass startup with the Shift key.

[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
CurrentDb.Properties("AppTitle")
will return it if it is set. See apptile property in access help for better explaination
 
gol4,

Thanks, but I didn't make myself clear. I need to compare the Application Title in Startup (which you showed me how to do) against the ACTUAL title showing on the screen (the Windows title bar).

When you open a database that has an "AppTitle" set, the contents of "AppTitle" show in the Windows title bar. However, if you open the database while holding the Shift key (to bypass Startup options) the Windows title bar shows "Microsoft Access".

I need to compare the current contents of the Windows title bar against the "AppTitle". If they match, I know that the Startup options were processed. If they don't match, I know that Shift was held down to suppress the Startup options.


[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
Thanks, gol4. Getting closer! This gives the title of the database window, but not the application. I had a feeling I'd have to deal with Windows API's in order to do this. Have a star for your help!


[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
Here you go

Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" ( _
ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long _
) As Long

Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" ( _
ByVal hwnd As Long _
) As Long


Private Function WindowTitle(ByVal lHwnd As Long) As String
Dim lLen As Long
Dim sBuf As String

' Get the Window Title:
lLen = GetWindowTextLength(lHwnd)
If (lLen > 0) Then
sBuf = String$(lLen + 1, 0)
lLen = GetWindowText(lHwnd, sBuf, lLen + 1)
WindowTitle = Left$(sBuf, lLen)
End If

End Function

Private Sub Command1_Click()
'just compare these 2
MsgBox WindowTitle(Application.hWndAccessApp)
MsgBox CurrentDb.Properties("AppTitle")
End Sub
 
Thanks! Have another star for the effort!

[shadeshappy] Cruising the Information Superhighway
(your mileage may vary)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top