ECHO Causing Problems

D

DS

I wrote a Macro using Echo On, Echo Off....It works great! I converted
it to code, It doesn't work so great, in fact it keeps freezing up the
screen. Whenever I take the Echo out of the equation it works fine but
I can see all of the action. Are there pitfalls with this Echo thing?
Any other way to do this?
Thanks
DS
 
D

Dirk Goldgar

DS said:
I wrote a Macro using Echo On, Echo Off....It works great! I
converted it to code, It doesn't work so great, in fact it keeps
freezing up the screen. Whenever I take the Echo out of the equation
it works fine but I can see all of the action. Are there pitfalls
with this Echo thing? Any other way to do this?

Show your code. Your "freezing up" problem could be due to an unhandled
error leaving Echo turned off, a message or prompt being displayed and
waiting for acknowledgement, but unseen because Echo is off, or just a
long-running process leaving the impression that you are locked up. Use
Echo False very sparingly, and extremely carefully.
 
D

DS

Dirk said:
Show your code. Your "freezing up" problem could be due to an unhandled
error leaving Echo turned off, a message or prompt being displayed and
waiting for acknowledgement, but unseen because Echo is off, or just a
long-running process leaving the impression that you are locked up. Use
Echo False very sparingly, and extremely carefully.
My Code........Thanks DS

On Error GoTo LogOnID_Err

DoCmd.Echo False, ""
' Open EmpID Log Form
DoCmd.OpenForm "EmpIDLog", acNormal, "", "", , acNormal
If (Forms!EmpIDLog!EmployeeID <= 0) Then
' Open Invalid ID Log On Form
DoCmd.OpenForm "InvalidIDLog", acNormal, "", "", , acNormal
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
' Close Log On Form
DoCmd.Close acForm, "LogOn"
' Stops Macro
Exit Sub
End If
' Opens Time Log Form
DoCmd.OpenForm "TimeLog", acNormal, "", "", , acNormal
If (IsNull(Forms!TimeLog!EmployeeID)) Then
' Opens Not Signed Log Form
DoCmd.OpenForm "NotSignedInLog", acNormal, "", "", , acNormal
' Close Time Log Form
DoCmd.Close acForm, "TimeLog"
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
' Close Log On Form
DoCmd.Close acForm, "LogOn"
' Stops Macro
Exit Sub
End If
If (Forms!EmpIDLog!EmployeeID > 0) Then
' Open Time Log Form
DoCmd.OpenForm "TimeLog", acNormal, "", "", , acNormal
' Go to Last Record of EmployeeID
DoCmd.GoToRecord , "", acLast
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
End If
If (Forms!TimeLog!DateOut > 0) Then
' Opens Not Signed In Log Form
DoCmd.OpenForm "NotSignedInLog", acNormal, "", "", , acNormal
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
' Close Time Log Form
DoCmd.Close acForm, "TimeLog"
' Close Log On Form
DoCmd.Close acForm, "LogOn"
' Stops Macro
Exit Sub
End If
If (IsNull(Forms!TimeLog!DateOut)) Then
' Opens Tables Form
DoCmd.OpenForm "Tables", acNormal, "", "", , acNormal
Forms!Tables!Text16 = Forms!LogOn!Display
' Close Time Log Form
DoCmd.Close acForm, "TimeLog"
' Close Log On
DoCmd.Close acForm, "LogOn"
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
Exit Sub
End If
DoCmd.Echo True, ""


LogOnID_Exit:
Exit Sub

LogOnID_Err:
MsgBox Error$
Resume LogOnID_Exit

End Sub
 
D

Dirk Goldgar

DS said:
My Code........Thanks DS

On Error GoTo LogOnID_Err

DoCmd.Echo False, ""
' Open EmpID Log Form
DoCmd.OpenForm "EmpIDLog", acNormal, "", "", , acNormal
If (Forms!EmpIDLog!EmployeeID <= 0) Then
' Open Invalid ID Log On Form
DoCmd.OpenForm "InvalidIDLog", acNormal, "", "", , acNormal
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
' Close Log On Form
DoCmd.Close acForm, "LogOn"
' Stops Macro
Exit Sub
End If
' Opens Time Log Form
DoCmd.OpenForm "TimeLog", acNormal, "", "", , acNormal
If (IsNull(Forms!TimeLog!EmployeeID)) Then
' Opens Not Signed Log Form
DoCmd.OpenForm "NotSignedInLog", acNormal, "", "", , acNormal
' Close Time Log Form
DoCmd.Close acForm, "TimeLog"
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
' Close Log On Form
DoCmd.Close acForm, "LogOn"
' Stops Macro
Exit Sub
End If
If (Forms!EmpIDLog!EmployeeID > 0) Then
' Open Time Log Form
DoCmd.OpenForm "TimeLog", acNormal, "", "", , acNormal
' Go to Last Record of EmployeeID
DoCmd.GoToRecord , "", acLast
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
End If
If (Forms!TimeLog!DateOut > 0) Then
' Opens Not Signed In Log Form
DoCmd.OpenForm "NotSignedInLog", acNormal, "", "", , acNormal
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
' Close Time Log Form
DoCmd.Close acForm, "TimeLog"
' Close Log On Form
DoCmd.Close acForm, "LogOn"
' Stops Macro
Exit Sub
End If
If (IsNull(Forms!TimeLog!DateOut)) Then
' Opens Tables Form
DoCmd.OpenForm "Tables", acNormal, "", "", , acNormal
Forms!Tables!Text16 = Forms!LogOn!Display
' Close Time Log Form
DoCmd.Close acForm, "TimeLog"
' Close Log On
DoCmd.Close acForm, "LogOn"
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
Exit Sub
End If
DoCmd.Echo True, ""


LogOnID_Exit:
Exit Sub

LogOnID_Err:
MsgBox Error$
Resume LogOnID_Exit

End Sub

All of those places before LogOnID_Exit where you execute the statement
"Exit Sub" will leave Echo set to False, resulting in an apparently
locked application. Also, if an error is raised, the Resume statement
in the error-handler is going to cause the procedure to exit without
resetting Echo to True. Furthermore, the error message won't be
visible, because Echo is still set to False at the moment it would be
displayed.

While I strongly suspect this code could be rewritten to check values in
tables rather than opening and closing forms just to read values from
them, that's beyond the scope of your question. Here's a minimally
revised version of your code:

'----- start of revised code -----
On Error GoTo LogOnID_Err

DoCmd.Echo False, ""

' Open EmpID Log Form
DoCmd.OpenForm "EmpIDLog", acNormal, "", "", , acNormal

If (Forms!EmpIDLog!EmployeeID <= 0) Then
' Open Invalid ID Log On Form
DoCmd.OpenForm "InvalidIDLog", acNormal, "", "", , acNormal
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
' Close Log On Form
DoCmd.Close acForm, "LogOn"
Else
' Opens Time Log Form
DoCmd.OpenForm "TimeLog", acNormal, "", "", , acNormal
If (IsNull(Forms!TimeLog!EmployeeID)) Then
' Opens Not Signed Log Form
DoCmd.OpenForm "NotSignedInLog", acNormal, "", "", ,
acNormal
' Close Time Log Form
DoCmd.Close acForm, "TimeLog"
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
' Close Log On Form
DoCmd.Close acForm, "LogOn"
Else
If (Forms!EmpIDLog!EmployeeID > 0) Then
' Open Time Log Form
DoCmd.OpenForm "TimeLog", acNormal, "", "", , acNormal
' Go to Last Record of EmployeeID
DoCmd.GoToRecord , "", acLast
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
End If
If (Forms!TimeLog!DateOut > 0) Then
' Opens Not Signed In Log Form
DoCmd.OpenForm "NotSignedInLog", acNormal, "", "", ,
acNormal
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
' Close Time Log Form
DoCmd.Close acForm, "TimeLog"
' Close Log On Form
DoCmd.Close acForm, "LogOn"
Else
If (IsNull(Forms!TimeLog!DateOut)) Then
' Opens Tables Form
DoCmd.OpenForm "Tables", acNormal, "", "", ,
acNormal
Forms!Tables!Text16 = Forms!LogOn!Display
' Close Time Log Form
DoCmd.Close acForm, "TimeLog"
' Close Log On
DoCmd.Close acForm, "LogOn"
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
End If
End If

End If

End If

LogOnID_Exit:
DoCmd.Echo True, ""
Exit Sub

LogOnID_Err:
DoCmd.Echo True, ""
MsgBox Error$
Resume LogOnID_Exit

End Sub
'----- end of revised code -----

Watch for line-wraps in the above, caused by the newsreader.

That ought to make it work without a major overhaul, but you wouldn't
need to turn echo off if you looked up values in tables (probably using
DLookup) rather than opening forms to get values from them.
 
D

DS

Dirk said:
All of those places before LogOnID_Exit where you execute the statement
"Exit Sub" will leave Echo set to False, resulting in an apparently
locked application. Also, if an error is raised, the Resume statement
in the error-handler is going to cause the procedure to exit without
resetting Echo to True. Furthermore, the error message won't be
visible, because Echo is still set to False at the moment it would be
displayed.

While I strongly suspect this code could be rewritten to check values in
tables rather than opening and closing forms just to read values from
them, that's beyond the scope of your question. Here's a minimally
revised version of your code:

'----- start of revised code -----
On Error GoTo LogOnID_Err

DoCmd.Echo False, ""

' Open EmpID Log Form
DoCmd.OpenForm "EmpIDLog", acNormal, "", "", , acNormal

If (Forms!EmpIDLog!EmployeeID <= 0) Then
' Open Invalid ID Log On Form
DoCmd.OpenForm "InvalidIDLog", acNormal, "", "", , acNormal
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
' Close Log On Form
DoCmd.Close acForm, "LogOn"
Else
' Opens Time Log Form
DoCmd.OpenForm "TimeLog", acNormal, "", "", , acNormal
If (IsNull(Forms!TimeLog!EmployeeID)) Then
' Opens Not Signed Log Form
DoCmd.OpenForm "NotSignedInLog", acNormal, "", "", ,
acNormal
' Close Time Log Form
DoCmd.Close acForm, "TimeLog"
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
' Close Log On Form
DoCmd.Close acForm, "LogOn"
Else
If (Forms!EmpIDLog!EmployeeID > 0) Then
' Open Time Log Form
DoCmd.OpenForm "TimeLog", acNormal, "", "", , acNormal
' Go to Last Record of EmployeeID
DoCmd.GoToRecord , "", acLast
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
End If
If (Forms!TimeLog!DateOut > 0) Then
' Opens Not Signed In Log Form
DoCmd.OpenForm "NotSignedInLog", acNormal, "", "", ,
acNormal
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
' Close Time Log Form
DoCmd.Close acForm, "TimeLog"
' Close Log On Form
DoCmd.Close acForm, "LogOn"
Else
If (IsNull(Forms!TimeLog!DateOut)) Then
' Opens Tables Form
DoCmd.OpenForm "Tables", acNormal, "", "", ,
acNormal
Forms!Tables!Text16 = Forms!LogOn!Display
' Close Time Log Form
DoCmd.Close acForm, "TimeLog"
' Close Log On
DoCmd.Close acForm, "LogOn"
' Close EmpID Log Form
DoCmd.Close acForm, "EmpIDLog"
End If
End If

End If

End If

LogOnID_Exit:
DoCmd.Echo True, ""
Exit Sub

LogOnID_Err:
DoCmd.Echo True, ""
MsgBox Error$
Resume LogOnID_Exit

End Sub
'----- end of revised code -----

Watch for line-wraps in the above, caused by the newsreader.

That ought to make it work without a major overhaul, but you wouldn't
need to turn echo off if you looked up values in tables (probably using
DLookup) rather than opening forms to get values from them.
Thanks Dirk,
But you say use DLookup...? I would love to not have to create and open
all of these forms, I suspect it would be a little cleaner!
Perhaps a little sample just to get me started....:)
Thanks
DS
 
D

Dirk Goldgar

DS said:
Thanks Dirk,
But you say use DLookup...? I would love to not have to create and
open all of these forms, I suspect it would be a little cleaner!
Perhaps a little sample just to get me started....:)
Thanks

Remember that data is stored in tables, not in forms -- forms only
*present* the data, for viewing and editing. You can examine this data
in code by opening recordsets on the the table (or on queries of the
tables ) -- this is the complicated way -- or by using the domain
aggregate functions DLookup, DMax, DMin, DSum, etc. -- this is the
simple way. If all your code needs is to know the value of one or more
fields in a table, there's no need to incur the overhead of opening a
user-interface object like a form.

It's impossible for me to give you a good working example, because I
don't know what tables or queries are the recordsources of your forms.
But look at this code of yours:
DoCmd.OpenForm "EmpIDLog", acNormal, "", "", , acNormal
If (Forms!EmpIDLog!EmployeeID <= 0) Then

It looks as though you are opening this form for two purposes: first,
to check whether there is an employee logged in, and then -- I think --
to provide that employee's EmployeeID to another form. For the first
purpose, code like this might suffice:

Dim lngEmployeeID As Long

lngEmployeeID = DLookup("EmployeeID", "tblEmpIDLog")

That assumes that "tblEmpIDLog" is the name of the table on which form
"EmpIDLog" is based, that it has a field named "EmployeeID", and that --
this is important -- there is no need to apply any criteria or sort to
get the specific record we need to look up. If it's necessary to apply
criteria to select a specific record, that can be done with DLookup. If
a sort is necessary, then you really need to use a query as the basis of
the DLookup, rather than the table itself.

It's hard to say exactly what to do about the second purpose -- if I've
guessed right about it at all -- because I don't know any of the
details. But suppose that it's form "TimeLog" that you want to open,
and that the recordsource of that form is currently a query that refers
to Forms!EmpIDLog!EmployeeID, like this:

SELECT * FROM tblTimeLog
WHERE EmployeeID = [Forms]![EmpIDLog]![EmployeeID];

If you changed that recordsource to just the table:

tblTimeLog

then you could open it to show records for the employee whose EmployeeID
you just looked up, like this:

DoCmd.OpenForm "TimeLog", _
WhereCondition:="EmployeeID = " & lngEmployeeID

That's the best I can do for an example, given how little I know about
your application's structure.
 

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