wierd command button quirk

M

martinmike2

Hello, I have a command button on a splash form that makes the user
accept a Privacy Act Statement. This command button opens 2 forms
(frmOFFLINE, frmMAIN) and then closes itself. Before I added
frmOFFLINE and only opened frmMAIN, the button work fine in one click,
but now that I have added frmOFFLINE to open hidden I now need to
click the button twice (not a double click, though that will work).

Private Sub Command6_Click()
DoCmd.OpenForm "frmMain"
DoCmd.OpenForm "frmOFFLINE", , , , , acHidden
DoCmd.Close acForm, Me.NAME
End Sub


any ideas?
 
O

OssieMac

I wonder why you are opening a form that is hidden for the purpose you
describe but I suppose you have your reasons.

Anyway, have you tried opening the hidden form first?
 
B

BruceM

I cannot duplicate the error in Access 2003. You could put a break point
into the code at:
DoCmd.OpenForm "frmMain"
to try to see the progression.

Does the second click open frmOffline, or does that happen with the second
click? In other words, what is the last thing that happens after the first
click? What happens if frmOffline is not hidden? Is frmOffline Pop-Up or
Modal? What happens if you explicitly name the form that is to close rather
than using Me.Name?
 
J

John Spencer

Is it possible that you have code in frmOFFLINE's open or load event that
closes frmMain?

You did not say which form opens on which click although since you are opening
frmOffLine hidden, then I might guess that frmMain is the one that is not
opening on th first click.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
M

martinmike2

Is it possible that you have code in frmOFFLINE's open or load event that
closes frmMain?

You did not say which form opens on which click although since you are opening
frmOffLine hidden, then I might guess that frmMain is the one that is not
opening on th first click.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County






- Show quoted text -

wow, lots of questions. Ok,

Ossie: frmOFFLINE queries a table called tblMAINT every two minutes
to check for "Maintenance Mode". If tblMAINT.OFFLINE = 1 then the
form unhides and displays a message asking all users to please exit
the system as it will be down for maintenance at such-n-such a time.
The reason the form opens hidden is because the user dosn't need to
see the form unless the system will be down for maintenance. The only
problem I have is that if the user has the computer locked the code
does not run and they will remain in the system. Since we do not
utilize logins there is no way for me to programmatically boot them
out of the system.


Bruce and John: It appears that frmOFFLINE opens first and then
frmMain opens after the second click. The idea was to have the user
click the "Accept" button only once and have both forms open.

The only code in the form is a command button to close the db and:
Private Sub Form_Current()
Dim Start, Wait
Dim rst As DAO.Recordset
Loops:
Wait = 120
Start = Timer
Do While Timer < Wait + Start
DoEvents
Loop
Set rst = CurrentDb.OpenRecordset("tblMaint")
If rst!Offline = 1 Then
With Forms(Me.NAME)
.Modal = True
.Visible = True
End With
Do While Now() < rst!Time
DoEvents
Loop
DoCmd.Quit
Else
GoTo Loops
End If
End Sub


frmOFFLINE is a pop-up but it is not modal, until it displays itself,
then it is a modal pop-up form. The only thing I still need to add to
the above code is to tell it to save all records before it closes.
 
B

BruceM

I would start by compiling the code, if you haven't already. After that I
would comment out that code and see what happens. It looks to me that the
loop run before the If statement begins. Assuming the loop works as
intended, why not just put it in the Else part of the If statement?

Else
Wait = 120
Start = Timer
Do While Timer < Wait + Start
DoEvents
Loop

Without knowing what rst!Time is, it is difficult to evaluate that loop, but
Time is a reserved word, which could cause problems unless it is in square
brackets (assuming it is a field).

If commenting out the code lets you open both forms, and if the suggestion
about moving the loop to Else makes sense, the next step may be to set a
break point at the start of each loop, and at the end of the last one, and
step through the code to identify the place where things go wrong.

Here are some links to code for kicking users off of the system:
http://www.accessmvp.com/JConrad/accessjunkie/kickoff.html

If you don't have a split database you should consider doing so.
http://allenbrowne.com/ser-01.html

Is it possible that you have code in frmOFFLINE's open or load event that
closes frmMain?

You did not say which form opens on which click although since you are
opening
frmOffLine hidden, then I might guess that frmMain is the one that is not
opening on th first click.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County






- Show quoted text -

wow, lots of questions. Ok,

Ossie: frmOFFLINE queries a table called tblMAINT every two minutes
to check for "Maintenance Mode". If tblMAINT.OFFLINE = 1 then the
form unhides and displays a message asking all users to please exit
the system as it will be down for maintenance at such-n-such a time.
The reason the form opens hidden is because the user dosn't need to
see the form unless the system will be down for maintenance. The only
problem I have is that if the user has the computer locked the code
does not run and they will remain in the system. Since we do not
utilize logins there is no way for me to programmatically boot them
out of the system.


Bruce and John: It appears that frmOFFLINE opens first and then
frmMain opens after the second click. The idea was to have the user
click the "Accept" button only once and have both forms open.

The only code in the form is a command button to close the db and:
Private Sub Form_Current()
Dim Start, Wait
Dim rst As DAO.Recordset
Loops:
Wait = 120
Start = Timer
Do While Timer < Wait + Start
DoEvents
Loop
Set rst = CurrentDb.OpenRecordset("tblMaint")
If rst!Offline = 1 Then
With Forms(Me.NAME)
.Modal = True
.Visible = True
End With
Do While Now() < rst!Time
DoEvents
Loop
DoCmd.Quit
Else
GoTo Loops
End If
End Sub


frmOFFLINE is a pop-up but it is not modal, until it displays itself,
then it is a modal pop-up form. The only thing I still need to add to
the above code is to tell it to save all records before it closes.
 
M

martinmike2

I would start by compiling the code, if you haven't already.  After that I
would comment out that code and see what happens.  It looks to me that the
loop run before the If statement begins.  Assuming the loop works as
intended, why not just put it in the Else part of the If statement?

Else
    Wait = 120
    Start = Timer
    Do While Timer < Wait + Start
        DoEvents
    Loop

Without knowing what rst!Time is, it is difficult to evaluate that loop, but
Time is a reserved word, which could cause problems unless it is in square
brackets (assuming it is a field).

If commenting out the code lets you open both forms, and if the suggestion
about moving the loop to Else makes sense, the next step may be to set a
break point at the start of each loop, and at the end of the last one, and
step through the code to identify the place where things go wrong.

Here are some links to code for kicking users off of the system:http://www.accessmvp.com/JConrad/accessjunkie/kickoff.html

If you don't have a split database you should consider doing so.http://allenbrowne.com/ser-01.html








wow, lots of questions.  Ok,

Ossie:  frmOFFLINE queries a table called tblMAINT every two minutes
to check for "Maintenance Mode".  If tblMAINT.OFFLINE = 1 then the
form unhides and displays a message asking all users to please exit
the system as it will be down for maintenance at such-n-such a time.
The reason the form opens hidden is because the user dosn't need to
see the form unless the system will be down for maintenance.  The only
problem I have is that if the user has the computer locked the code
does not run and they will remain in the system.  Since we do not
utilize logins there is no way for me to programmatically boot them
out of the system.

Bruce and John:  It appears that frmOFFLINE opens first and then
frmMain opens after the second click.  The idea was to have the user
click the "Accept" button only once and have both forms open.

The only code in the form is a command button to close the db and:
Private Sub Form_Current()
Dim Start, Wait
Dim rst As DAO.Recordset
Loops:
Wait = 120
Start = Timer
Do While Timer < Wait + Start
DoEvents
Loop
Set rst = CurrentDb.OpenRecordset("tblMaint")
If rst!Offline = 1 Then
    With Forms(Me.NAME)
        .Modal = True
        .Visible = True
    End With
    Do While Now() < rst!Time
        DoEvents
    Loop
    DoCmd.Quit
Else
    GoTo Loops
End If
End Sub

frmOFFLINE is a pop-up but it is not modal, until it displays itself,
then it is a modal pop-up form.  The only thing I still need to add to
the above code is to tell it to save all records before it closes.- Hide quoted text -

- Show quoted text -

I solved this by having the command button only open frmOFFLINE, and
having frmOFFLINE_Load event open frmMAIN, hide itself, and close
frmSplash.
 
B

BruceM

Glad to hear you found a workaround. The loop runs every time you run the
code as written, and it happens again if the Else condition is met, so I
suspect it would not have done what you intended anyhow. However, opening
one form from another is a reasonable approach.

I would start by compiling the code, if you haven't already. After that I
would comment out that code and see what happens. It looks to me that the
loop run before the If statement begins. Assuming the loop works as
intended, why not just put it in the Else part of the If statement?

Else
Wait = 120
Start = Timer
Do While Timer < Wait + Start
DoEvents
Loop

Without knowing what rst!Time is, it is difficult to evaluate that loop,
but
Time is a reserved word, which could cause problems unless it is in square
brackets (assuming it is a field).

If commenting out the code lets you open both forms, and if the suggestion
about moving the loop to Else makes sense, the next step may be to set a
break point at the start of each loop, and at the end of the last one, and
step through the code to identify the place where things go wrong.

Here are some links to code for kicking users off of the
system:http://www.accessmvp.com/JConrad/accessjunkie/kickoff.html

If you don't have a split database you should consider doing
so.http://allenbrowne.com/ser-01.html








wow, lots of questions. Ok,

Ossie: frmOFFLINE queries a table called tblMAINT every two minutes
to check for "Maintenance Mode". If tblMAINT.OFFLINE = 1 then the
form unhides and displays a message asking all users to please exit
the system as it will be down for maintenance at such-n-such a time.
The reason the form opens hidden is because the user dosn't need to
see the form unless the system will be down for maintenance. The only
problem I have is that if the user has the computer locked the code
does not run and they will remain in the system. Since we do not
utilize logins there is no way for me to programmatically boot them
out of the system.

Bruce and John: It appears that frmOFFLINE opens first and then
frmMain opens after the second click. The idea was to have the user
click the "Accept" button only once and have both forms open.

The only code in the form is a command button to close the db and:
Private Sub Form_Current()
Dim Start, Wait
Dim rst As DAO.Recordset
Loops:
Wait = 120
Start = Timer
Do While Timer < Wait + Start
DoEvents
Loop
Set rst = CurrentDb.OpenRecordset("tblMaint")
If rst!Offline = 1 Then
With Forms(Me.NAME)
.Modal = True
.Visible = True
End With
Do While Now() < rst!Time
DoEvents
Loop
DoCmd.Quit
Else
GoTo Loops
End If
End Sub

frmOFFLINE is a pop-up but it is not modal, until it displays itself,
then it is a modal pop-up form. The only thing I still need to add to
the above code is to tell it to save all records before it closes.- Hide
quoted text -

- Show quoted text -

I solved this by having the command button only open frmOFFLINE, and
having frmOFFLINE_Load event open frmMAIN, hide itself, and close
frmSplash.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top