Re: on change event hang

alicejwz

Registered User.
Local time
Today, 13:19
Joined
Jul 9, 2003
Messages
91
Re: on change event hang

Hi everyone,

I was wondering if anyone could some insight on my problem.

I'm using AC2K and SQL Server 2K. I copied my FE onto the user's machine. The user's machine has similiar storage space & RAM and configuration as mine. There are two text boxes on the form w/ on change events When I try test the code it hangs from 8 seconds to 30 seconds on both of these controls.
I stepped thru the code it ran Exit Sub in the subroutines and hangs.

Exit_msp_barcode_Change:
-->Exit Sub

Err_msp_barcode_Change:
MsgBox err.Description
Resume Exit_msp_barcode_Change
End Sub

Why??
I appreciate any suggestions.
 
Is this TextBox part of a search by chance? The OnChange event occurs after every keystroke. Do you care to post the complete OnChange code?
 
Hi RuralGuy,

Thanks for your reply.
I just found out is the setfocus method causing the application to hang. I don't understand why or how I can fix this. I would appreciate your help. Thanks!

Here is my code:
Private Sub msp_barcode_Change()
On Error GoTo Err_msp_barcode_Change
Dim bag_n As Integer
Dim get_prev_bag_info As New ADODB.Command
Call load_const

If Len(Trim(Me!msp_barcode.Text)) = CInt(work_ord_num_length) + CInt(work_ord_line_num_length) Then
Me!work_ord_num.Value = Left(Me!msp_barcode.Text, 9)
Me!work_ord_line_num.Value = Right(Me!msp_barcode.Text, 3)
Call get_bag(Left(Me!work_ord_num.Value, 6), Me!work_ord_line_num.Value, get_prev_bag_info)
Set get_prev_bag_info = Nothing

If Me!bag_num.Value <> "1" Then
Me!unb_bag_quantity.SetFocus

Else
Me!material_lotnum.Value = ""
Me!insert_lotnum.Value = ""
Me!mfg_dt.Value = ""
Me!material_lotnum.SetFocus
End If
End If


Exit_msp_barcode_Change:
Exit Sub

Err_msp_barcode_Change:
MsgBox err.Description
Resume Exit_msp_barcode_Change
End Sub
 
I would think the AfterUpdate event would be a more appropriate event to put this code in. Running this much code and changing the focus for every keystroke would seem like an accident waiting to happen. There are two calls in here also so no telling how much code is executing. You could easily be up against a timimg issue.
 
Re: on change event/setfocus hangs

Hi RuralGuy,

Thanks for quick reply.
I don't think the rest of the code will run including setfocus in the change event unless the If statement is true
If Len(Trim(Me!msp_barcode.Text)) = CInt(work_ord_num_length) + CInt(work_ord_line_num_length) Then

I also removed all the code except .setfocus in the change event and it still hangs.

This is so strange and frustrating.
It works fine on my machine. I also checked the reference on user's machine.
Is it the code or something else?
Any more good advise?
Thanks!
 
Re: on change/setfocus hangs

I will not be able to use AfterUpdate event, I need to move to the next field after user types the first and second field. Thanks!
 
As a diagnostic, try the following and see if it still hangs:
Code:
Private Sub msp_barcode_Change()
On Error GoTo Err_msp_barcode_Change
[B]Exit Sub[/B]
 

Users who are viewing this thread

Back
Top Bottom