Weird problem, code works with in built however in VBA doesnt. (1 Viewer)

bitsbb01

Registered User.
Local time
Today, 10:38
Joined
Apr 2, 2013
Messages
34
Good Morning everyone..

Ok i've come accross a weird problem.. lol

i have a countdown on 1 of my main startup forms, that checks to see if outlook is running if not then it'll auto start-it outlook, then when the counter gets to 0 it continues to load the main menu...

Now if i have a button on the form that shows only when all the checks are done, that button works fine using the inbuilt macro builder.. and opens the main menu..

However in VBA it doesnt show the main menu, in fact its like the main menu is hidden, however using the same commands..

it also does the same when the countdown ends..

Heres the Code:-

Code:
Option Compare Database
Public Loops As Integer

Private Sub Form_Open(Cancel As Integer)
 Me.TimerInterval = 1000
 Form_Timer
    
    CurrentDb.Properties("AllowShortcutMenus") = False
  Call fSetAccessWindow(2)
  
Dim i As Integer
For i = 1 To CommandBars.count
CommandBars(i).Enabled = True
Next i
    DoCmd.ShowToolbar "Menu Bar", acToolbarYes
DoCmd.SelectObject acTable, , True
    
If (fIsAppRunning("Outlook")) = False Then
'    If outlook is not running, open in..
RetVal = Shell("C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE", 1)
Me.Label0.Visible = False
Me.Label1.Visible = False
Me.Label3.Visible = True
Me.Label4.Visible = True
Me.ExitStarter.Visible = True
    
            Exit Sub
    Else
Me.Label0.Visible = False
Me.Label1.Visible = False
Me.Label5.Visible = True
Me.Label6.Visible = True
Me.ExitStarter.Visible = True
    'MsgBox "Outlook is running"
    
    End If
    
End Sub

Private Sub Form_Timer()
Static StartTime As Date
Dim SecondsToCount As Integer
SecondsToCount = 5 'Set this variable to the total number of seconds to count down
If Loops = 0 Then StartTime = Time
 
 Min = (SecondsToCount - DateDiff("s", StartTime, Time)) \ 60
 Sec = (SecondsToCount - DateDiff("s", StartTime, Time)) Mod 60
 Me.TimeLeft.Caption = "Form will close in " & Min & ":" & Format(Sec, "00")
 Loops = Loops + 1
 If Me.TimeLeft.Caption = "Form will close in 0:00" Then
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "frmMenu", acNormal
End If
End Sub

and heres the code from the macro builder..

Code:
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<UserInterfaceMacros xmlns="[URL]http://schemas.microsoft.com/office/accessservices/2009/11/application"><UserInterfaceMacro[/URL] For="ExitStarter" Event="OnClick"><Statements><Action Name="OpenForm"><Argument Name="FormName">frmMenu</Argument></Action><Action Name="CloseWindow"><Argument Name="ObjectType">Form</Argument><Argument Name="ObjectName">DBStarter</Argument><Argument Name="Save">No</Argument></Action></Statements></UserInterfaceMacro></UserInterfaceMacros>

i am stumped, as cannot work out why it'll do it manualy, however wont show it using vba, however other forms will load fine.. and yes the main menu has a lot more coding on it.. but i can have that open from buttons, or from main startup in Access...

Any Ideas??

PS. i included the copy of the VBA for the main menu.. yes it probably could be cleaned up, but at momment i'm still building it and been a long time since i've done a lot in VBA.. anyway its included if you think it might be the main menu...
 

Attachments

  • The_Main_Menu_VBA.txt
    17.8 KB · Views: 209

MarkK

bit cruncher
Local time
Today, 08:38
Joined
Mar 17, 2004
Messages
8,181
I don't get why you need a timer. Just do the jobs you need to do, then do the next one.

Code:
[SIZE="2"]Private Sub Form_Open(Cancel As Integer)
    Dim i As Integer
    
    CurrentDb.Properties("AllowShortcutMenus") = False
    Call fSetAccessWindow(2)
  
    For i = 1 To CommandBars.Count
        CommandBars(i).Enabled = True
    Next i
    DoCmd.ShowToolbar "Menu Bar", acToolbarYes
    DoCmd.SelectObject acTable, , True
    
    If Not fIsAppRunning("Outlook") Then
        Shell "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE", 1
    End If
    
    DoCmd.Close acForm, Me.Name
    DoCmd.OpenForm "frmMenu", acNormal
    
End Sub[/SIZE]
 

bitsbb01

Registered User.
Local time
Today, 10:38
Joined
Apr 2, 2013
Messages
34
because wanted them to see the notice that pops up, letting them know that they need to keep Outlook open due to being used in the DB..

Also if i do that excatly like you've shown it doesnt show the frmMenu at all..
 

MarkK

bit cruncher
Local time
Today, 08:38
Joined
Mar 17, 2004
Messages
8,181
It is a common error for programmers to think users care what is happening "under the hood." I suggest you do your best to look at the process from a users' perspective and eliminate all gratuitous message boxes, indicators, and warnings. Users not only don't care, messages about what is happening make them nervous.

Also, if your application needs an instance of Outlook running that the user cannot kill, then create a hidden instance. I think you can do something like . .

Code:
dim ol as new outlook.application
[COLOR="Green"]'show it to the user[/COLOR]
ol.visible = true
[COLOR="Green"]'hide it from the user[/COLOR]
ol.visible = false

And if frmMenu is not opening, what is the code in the Open or Load events of that form? Is it opening hidden, so is some other process hiding it? Does the code that should open it even complete?

hth
 

bitsbb01

Registered User.
Local time
Today, 10:38
Joined
Apr 2, 2013
Messages
34
ok, opening the Main form on its own works fine, but yes it does have code, none to make it hidden though. see the text included in first post..

We've been using this for awhile with no problems, i'm just trying to clean up things.. etc and also having it automaticly goto to the main menu after 5 seconds..

however i have seen that it does seem to be the main menu.. the question is what...
 

Users who are viewing this thread

Top Bottom