howardsd
asked on
form reloads on it's own
i have a form that has a timer control. in the form_unload procedure i make the timer.enabled=false. sometimes the form reloads immediately after it's form_unload completes (happens intermittenylty, maybe once out 10, always randomly). i have a feeling that even though the timer is disabled, a function that is called in the timer has not finished and is referencing a control's event after the form has unloaded, therefore the form reloads to facilitate the event.
is this plausible? and if so how can one prevent this from happening?
is this plausible? and if so how can one prevent this from happening?
Do you have doevents in your code?
ASKER
no
Is disabling the timer the only thing in your form_unload procedure? And when the form reloads, is the timer enabled or disabled?
shows us the queryunload routine
ASKER
here's the unload routine. in the form_load routine the timer gets enabled.
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo err
Timer1.Enabled = False
If dbvalueconnection.state = adStateOpen Then
dbvalueconnection.Close
End If
closeRecordsets rsvalueread, rsvalueidread
Screen.MousePointer = vbDefault
Set dbvalueconnection = Nothing
Set rsvalueread = Nothing
Set rsvalueidread = Nothing
Exit Sub
err:
If err <> 0 Then
MsgBox err.Source & "-->" & err.Description, vbOKOnly, "Form unload failure"
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo err
Timer1.Enabled = False
If dbvalueconnection.state = adStateOpen Then
dbvalueconnection.Close
End If
closeRecordsets rsvalueread, rsvalueidread
Screen.MousePointer = vbDefault
Set dbvalueconnection = Nothing
Set rsvalueread = Nothing
Set rsvalueidread = Nothing
Exit Sub
err:
If err <> 0 Then
MsgBox err.Source & "-->" & err.Description, vbOKOnly, "Form unload failure"
End If
End Sub
Try putting a Sleep in there (after the disabling) to delay the rest of the events...
ASKER
with a Sleep(2000) i get the same result. i close the form, its waits 2 seconds, closes, then the form pops right back up. still occuring randomly, no real pattern for when it does/doesn't happen).
I think you need to show us what is in the Timer routine.
Idle_Mind
Idle_Mind
ASKER
Private Sub Timer1_Timer()
Dim d As String
d = String(200, 0)
l = SCardComand(0, "Card,Info,Status", 0, nil, 0, d, 200)
d = Left(d, InStr(d, Chr(0)) - 1)
If l = 0 Then
If d = "active" Then
cardStatus.Caption = "card in reader"
If iSnglRead = False Then
' if no problems during read and loyalty id the active screen make form able
If fillForm = True Then
cmdAdd.Enabled = True
cmdSub.Enabled = True
cmdWriteCustCrd.Enabled = True
cmdWriteRetailerCrd.Enable d = True
End If
iSnglClr = False
iSnglRead = True
End If
ElseIf d = "wait" Then
cardStatus.Caption = "insert card"
If iSnglClr = False Then
Call clearControlsValue
lblCardHolder.Caption = ""
cmdAdd.Enabled = False
cmdSub.Enabled = False
cmdWriteCustCrd.Enabled = False
cmdWriteRetailerCrd.Enable d = False
iSnglClr = True
iSnglRead = False
End If
Else
cardStatus.Caption = d
cmdAdd.Enabled = False
cmdSub.Enabled = False
End If
End If
End Sub
Dim d As String
d = String(200, 0)
l = SCardComand(0, "Card,Info,Status", 0, nil, 0, d, 200)
d = Left(d, InStr(d, Chr(0)) - 1)
If l = 0 Then
If d = "active" Then
cardStatus.Caption = "card in reader"
If iSnglRead = False Then
' if no problems during read and loyalty id the active screen make form able
If fillForm = True Then
cmdAdd.Enabled = True
cmdSub.Enabled = True
cmdWriteCustCrd.Enabled = True
cmdWriteRetailerCrd.Enable
End If
iSnglClr = False
iSnglRead = True
End If
ElseIf d = "wait" Then
cardStatus.Caption = "insert card"
If iSnglClr = False Then
Call clearControlsValue
lblCardHolder.Caption = ""
cmdAdd.Enabled = False
cmdSub.Enabled = False
cmdWriteCustCrd.Enabled = False
cmdWriteRetailerCrd.Enable
iSnglClr = True
iSnglRead = False
End If
Else
cardStatus.Caption = d
cmdAdd.Enabled = False
cmdSub.Enabled = False
End If
End If
End Sub
ASKER
the fillForm function reads a smart card and fills the form with the contents of the card
add in the unload:
set form1 = nothing ' where form1 is the name of the form
set form1 = nothing ' where form1 is the name of the form
Where is the form being controlled from? Is it the main form of the program, or is there another form or procedure that opens it? If the second is true, then is there any call being made to the form by the form that called it?
ASKER
this is the main form, but it is loaded by a splash form that flashes the user when the app is started. here is the form_load procedure for the splash form
valueSplash is the splash form (duh)
loyalty is the main form
Private Sub Form_Load()
valueSplash.Show 0
Refresh
Sleep 2500
valueSplash.Hide
Unload valueSplash
Load loyalty
End Sub
valueSplash is the splash form (duh)
loyalty is the main form
Private Sub Form_Load()
valueSplash.Show 0
Refresh
Sleep 2500
valueSplash.Hide
Unload valueSplash
Load loyalty
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that seemed to have done it. i tested 30 times without the occurence whereas before it happened at least 1 in 10
thnx!!!
thnx!!!
No Problem.
Glad I could help.
Idle_Mind
Glad I could help.
Idle_Mind