Display Database Window

sts023

Registered User.
Local time
Today, 02:23
Joined
Dec 1, 2010
Messages
40
Hi guys....

I'm trying to achieve a form displayed at startup which has several command buttons, one of which is "Display Database Window".
I looked at the example in the Northwind database.
Code:
Sub DisplayDatabaseWindow_Click()
' This code created in part by Command Button Wizard.
On Error GoTo Err_DisplayDatabaseWindow_Click
    Dim strDocName As String
 
    strDocName = "Categories"
    ' Close Main Switchboard form.
    DoCmd.Close
 
    ' Give focus to Database window; select Categories table (first
    ' form in list).
    DoCmd.SelectObject acTable, strDocName, True
 
Exit_DisplayDatabaseWindow_Click:
    Exit Sub
Err_DisplayDatabaseWindow_Click:
    MsgBox Err.Description
    Resume Exit_DisplayDatabaseWindow_Click
 
End Sub
In my scenario, I don't want to close the original form, so I commented out the "DoCmd.Close". Worked perfectly.
On reading the Help files, I discovered that I could remove the references to StrDocName, provided that the InDatabaseWindow option was still set to True.
I changed that line of code to read
Code:
  DoCmd.SelectObject acTable, , True
and everything still works fine.

Finally, in Tools/Startup I unchecked the Display Database Window box.
Now, when I start Northwind, I get the "Main Switchboard" form with no Database Window, but on hitting the button, the Database Window appears.
Perfect!

Then I copied the code into my development database.

Now, when I hit the button on my development database, I get the following message :-
"The expression On Click you entered as the event property setting produced the following error:
Procedure Declaration does not match description of event or procedure having the same name.
*The expression may not result in the name of a macro, the name of a user defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro"

I've checked the References section in both databases - they're identical.

In case I've missed something obvious, my code is as below
Code:
Private Sub DisplayDatabaseWindow_Click()
On Error GoTo Err_DisplayDatabaseWindow_Click
'Give focus to Database window;
'select Categories "table" (operand is acTable),
'which is the first form in the list.
  DoCmd.SelectObject acTable, , True
Exit_DisplayDatabaseWindow_Click:
    Exit Sub
Err_DisplayDatabaseWindow_Click:
    MsgBox Err.Description
    Resume Exit_DisplayDatabaseWindow_Click
 
End Sub

Can anyone help?
 
When you're in a code window, what happens if you click MainMenu->Debug->Compile? Does this highlight a problem in code?
 
Hi guys, and a big thanks to all responders, especially lagbolt.

Yes, I’d also slipped in some simple code to Exit Access, but got the declaration wrong! That was what was throwing up the error message :o!

I guess I still tend to think that whatever I’m trying to run is causing the problem: why I didn’t compile the code is beyond me – I usually compile frequently to pick up typos etc.

Perhaps it’s because I still tend to think that proper code lives in Modules (yes, I know it’s silly – I’m just being honest here!) :eek:

Anyway, if this post just persuades those new to Access VBA to compile everything frequently, it may help someone else.

Thanks again guys (until the next time….)
 
Well, this is an unusual case. Normally the compiler won't let you run any code while there is an unresolved error, and in that case it highlights the line in question immediately.
But this error is an odd-ball. You can cause it by changing the signature of a known event handler like Form_Open(). Remove the 'Cancel As Integer' parameter like so ...
Code:
Private Sub Form_Open()
End Sub
Notice that you can open any other form and run any other code and the compiler has no complaint. Open the form in question and you get the error you got, but still no indication of where the error is.
In this case only if you explicitly debug->compile will you find the problem.
 

Users who are viewing this thread

Back
Top Bottom