Unexpected Error

I have a formA which opens formB.

Sometimes on formB I am getting an unexpected error # 50003 in a function which is called from my form_activate.  The error comes from me doing a formB.refresh.  I have no clue why it would sometimes cause this.  it happens maybe once a day or once every 2 days.

Therefore, I'm getting this error in this function, in form_activate and then back in formA in the function which showed formB.

Then every time a user tries to open this screen it continues to give this error.

The error is cleared only after the program is closed and restarted.

Is there a way I can clear this error out so that it stops firing?
Fraser_AdminAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

z3r3Commented:
i'd guess that form "b" is not yet active or showing on screen when doing the refresh. Perhaps check if form is showing or visible before doing the refresh.
0
Fraser_AdminAuthor Commented:
how would i do that?  if frmB.visible then....
0
z3r3Commented:
yes. I would go that route and see if it helps. I've had a couple issues in both VB 6 and DELPHI where working with the form before it was displayed caused problems. You'll probably find that occasionally events are firing in an order that you aren't expecting. If you still have a problem perhaps adding a doevents prior to the refresh and visible check could help as it clears the message queue and lets things get processed.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Fraser_AdminAuthor Commented:
ok when i did this, i also noticed that one of my functions had the on error commented out.  So I uncommented this, and then noticed that the error is actually fired when i'm showing the form.  i suppose before it was giving the problem on the refresh since the showing of the form caused an error.

I have a doevents directly before showing the form.  But I have several properties of the form that I'm setting before i do the doevents..

frm1.prop1 = "prop1"
frm1.prop2 = "prop2"
doevents
frm1.show 1 ---The error happens here, not every time, but sometimes.

Any other suggestions here?
0
z3r3Commented:
ok, I can get an idea on why the error is occuring. if you can give me some sample code here it would help. That doevents won't help you where you have it because it applies to the current form not the one being shown, which is where you are having issues. I'm guessing that when you are doing some of the setups the form is already being shown and certain items run on form 2 then your actual show is causing a reshow of the form and the events fired on form 2 are having there code re-run in the activate which is freaking VB out.

I need to know how the second form being called and shown from the first one. Then I need to what you doing in the initial functions that are called when the form is created and shown i.e. form create, form activate, form show. I have encountered similar issues to what you are describing so we will be able to solve it. Occasionally I've had to use timers to sort it out but the issues have all been solvable so bear with me and I'm sure we'll figure it out.
0
Fraser_AdminAuthor Commented:
is there a way i can check if the second form is loaded showing before showing it.  it is definitly not visible, but maybe it is keeping something in memory or something.

There is a lot of code.  Which would you like to see?

It just sucks cause i'm getting lots of pressure becuase this is an unmanned ap, so everytime this happens people are called in at overtime.
This is a snippet of what called the form.  The errSpot I see in my error log is Show frmScale before.  So I don't think it is actually getting to the part where it is showing.  My Form_Load and Form_Activate events also have error handlers and nothing is coming up from them.
 
If (UCase(PROGRAM_TYPE) = UCase("A") Or UCase(PROGRAM_TYPE) = UCase("S")) And ctlScale1.AllowWeightReading = True Then
      errSpot = "Automatic"
      sndPlaySound App.path & "\card.wav", SND_ASYNC Or SND_NODEFAULT
      errSpot = "Close Port Before"
      ClosePort
      errSpot = "Close Port After"
      frmScale.Card = mCard
      frmScale.GrossWeight = mGrossWeight
      frmScale.AssignSequenceDate = 0
      frmScale.ScaledGross = "0"
      frmScale.ScaledDeductions = "0"
      SCALE_FORM_ACTIVATE = False
      ACTIVE_FORM = "frmScale"
      DoEvents
      errSpot = "Show frmScale before"
      frmScale.Show 1
      errSpot = "Show frmScale after"
      ACTIVE_FORM = "frmCard"

Open in new window

0
z3r3Commented:
ok maybe you do checks with the form but if not you might want to try the following code. If you still having issues then we need to look at the events inside the form being opened to see if we can get any clues as to where the problem lies. That doevents doesn't help you. I as only intending it to be used within the scale form itself.


        'Ensure we using a clean copy of the form
        If frmScale.Enabled Then Unload frmScale
        Load frmScale
        
        frmScale.Card = mCard
        frmScale.GrossWeight = mGrossWeight
        frmScale.AssignSequenceDate = 0
        frmScale.ScaledGross = "0"
        frmScale.ScaledDeductions = "0"
        
        'Something in form may trigger it being showed so...
        If Not frmScale.Visible Then frmScale.Show vbModal, Me

Open in new window

0
Fraser_AdminAuthor Commented:
I made the change and I will see what happens, sometimes it is a couple of days later before the error happens.  how is it possible that it is even executing any code within the second form if i'm not catching any errors?  i have error handlers in my form_load and activate events, so if it was getting into that form at all wouldn't it trigger the error.  anyways hopefully this will fix up the problem once and for all.  
0
z3r3Commented:
If I remember correctly from the last time I got that error, the error you getting is not being handled by VB in the regular fashion and you might not be going into the normal error handlers for that form. BUT let me know what happens. If it doesn't work we'll try the next step :-)
0
Fraser_AdminAuthor Commented:
OK same thing.  See what happens is on formB i have a refresh.  THis is where the error is initially coming from.  Then everytime there after I cannot open the form, its like it is corrupted or something.  Everytime I try it throws this unexpected error.  The error from the refresh is also unexpected error.  I close out and reopen the program all is fine.  It ran for about 20 hours before this occured.
0
z3r3Commented:
1) So you using my load and unload code to ensure you always have a clean copy of the form when opening the form and it still needs the application to be restarted?

2) Ok what i need then is to know what event the refresh occurs in and i need to see the code inside that event.
0
Fraser_AdminAuthor Commented:
OK here is what happens, the first form a user scans his card using a keyboard wedge, once the card has been checked against the database and verified, the input form is activated (using the code you supplied me).  This form stores all the information that the user selects.  There are several options preset on a card which indicate what to prompt the user for.  So once the second form loads it selects from the database to see what to prompt the user for (cards can prompt for different things).  So basically this program is huge and all inner links so i'm not sure what all to provide you with.  Provide me with an email address if you want more.  I took code snippets from the functions as the functions are too large to post here.

The error first occurs on the refresh of the second form (in the weigh in function first, then the form_activate event handler second).  Then every time the user scans his card (which executes the code you provided) i get the same error.  but only when opening frmScale.  if i open a different form (some cards open another form first to prompt for another option before going to frmScale), no problem to open other forms.  just the frmScale causes the problem.  thats what leaves me to believe that it is corrupted.

The other strange thing is i have a class that i created to store all the values that the user selects.  When the second form comes up i store the card number there, so the code being sr.cardnumber = mcard (where mcard is a var accessing a property on my page).  so when this code executes that is causing the problem, i have it printing to an error log, and the card number would never show up using sr.cardnumber.  so i put in an if (iif sr.cardnumber = "" then don't refresh the page).  i also have it printing mcard & "-" when sr.cardnumber = "" in my error log.  so for some strange reason, when this happens my cardnumber is not filled into my class and therefore i see the "-" after my card number.  

Attached is my code for the calling of the form.  This sub-routine gets executed when a user scans a card (after the card has been verified, etc.)  In my error log I see errSpot = Close Port After.  So the error occured after that assignment.

I also attached the code for the weigh in function which is called in the form activate (also attached).  The errSpot = Refresh Before on the weighin and Refresh Before 6 on the Form_activate.  In my error log you see the cardnumber = 5183-, so it is strange that it even called the refresh.

Hope I provided you with enough information.
Private Sub OpenScaleWindow()
frmCard procedure
   On Error GoTo StartError
   
   Dim errSpot As String
   sndPlaySound App.path & "\card.wav", SND_ASYNC Or SND_NODEFAULT
   errSpot = "Close Port Before"
   ClosePort
   errSpot = "Close Port After"
   If frmScale.Enabled Then Unload frmScale
   Load frmScale
   frmScale.Card = mCard
   frmScale.GrossWeight = mGrossWeight
   frmScale.AssignSequenceDate = 0
   frmScale.ScaledGross = "0"
   frmScale.ScaledDeductions = "0"
   SCALE_FORM_ACTIVATE = False
   ACTIVE_FORM = "frmScale"
   errSpot = "Show frmScale before"
   If Not frmScale.Visible Then frmScale.Show vbModal, Me
   errSpot = "Show frmScale after"
   ACTIVE_FORM = "frmCard"
ExitSub:
   Exit Sub
StartError:
   Dim sDescription As String
   Dim sNumber As String
   sDescription = Err.Description
   sNumber = Err.Number
   WriteErrorToDB sDescription, sNumber, "frmCard", "OpenScaleWindow", ctlKeyBoard1.KeyBoard_Input, SCALE_ID, errSpot
   If mCard <> "" Then
      RemoveCardScanned (mCard)
   End If
   If sNumber = 50003 Then
      MsgBox ("An unexpected error occurred.  Please close and restart the scales program.")
      ctlKeyBoard1.KeyBoard_Input = ""
      ctlKeyBoard1.SetTextboxFocus = True
   End If
      
   Resume ExitSub
End Sub
 
 
 
 
 
 
Private Sub WeighIn(bAll As Boolean, UpdateClicked As Boolean, FieldName As String)
'frmScale procedure
    On Error GoTo StartError
    txtProcessing.Visible = True
    Dim strsql As String
    Dim errSpot As String
    
    cmdSave.Enabled = False
    CheckFieldsDone
     
    If Not bLanguageDone Then DoLanguage
    If (bLanguageDone And Not bWeighMasterDone) Then DoWeighMaster (bAll)
    errSpot = "WeighMaster"
    If (bWeighMasterDone And Not bHaulingContractDone And _
        (UCase(PROGRAM_TYPE) = UCase("M") Or (cv.strCardHaulingContractInOut = "In" And sr.CardStatus = "Open")) Or (UpdateClicked And FieldName = "HaulingContract")) Then DoHaulingContract (bAll)
    errSpot = "HaulingContract"
    If (bHaulingContractDone And Not bProductContractDone And _
        (UCase(PROGRAM_TYPE) = UCase("M") Or (cv.strCardProductContractInOut = "In" And sr.CardStatus = "Open")) Or (UpdateClicked And FieldName = "ProductContract")) Then DoProductContract (bAll)
    errSpot = "ProductContract"
    If (bProductContractDone And Not bLoadingContractDone And _
        (UCase(PROGRAM_TYPE) = UCase("M") Or (cv.strCardLoadingContractInOut = "In" And sr.CardStatus = "Open")) Or (UpdateClicked And FieldName = "LoadingContract")) Then DoLoadingContract (bAll)
    errSpot = "LoadingContract"
 
.......'Does this for each thing we prompt for
 
    If AllFieldsDone Then
       cmdSave.Enabled = True
       If cv.strCardShowSave = "No" Then
          errSpot = "Save Before"
          SaveScale
          errSpot = "Save After"
          frmCard.ctlScale1.ScaleStatus = "Exiting"
          errSpot = "Print Picture Before"
          PrintPictureRoutine
          errSpot = "Print Picture After"
       End If
    End If       
    bScanned = False
    txtProcessing.Visible = False
    errSpot = "Refresh Before"
    If frmScale.Visible And sr.CardNumber <> "" Then
       frmScale.Refresh
    End If
    errSpot = "Refresh After"
      
ExitSub:
   Exit Sub
StartError:
   Dim sDescription As String
   Dim sNumber As String
   sDescription = Err.Description
   sNumber = Err.Number
   MsgBox sDescription & " Subroutine: frmScale.WeighIn"
   WriteErrorToDB sDescription, sNumber, "frmScale", "WeighIn", IIf(sr.CardNumber = "", mCard & "-", sr.CardNumber), SCALE_ID, errSpot, sr.ProfileDescription
   Resume ExitSub
 
End Sub
 
 
 
 
Private Sub Form_Activate()
'Activate event of frmScale
On Error GoTo StartError
      Dim errSpot As String
      
      errSpot = "Just Beginning"
      
      Timer1.Interval = 750
            
      sr.CardNumber = mCard
 
                 
      If sr.CardStatus = "Open" Then
         bSetFields = False
         errSpot = "CardStatus = Open or Update"
         errSpot = "Refresh 4 Before"
         If frmScale.Visible And sr.CardNumber <> "" Then
            frmScale.Refresh
         End If
         errSpot = "Refresh 4 After"
         WeighIn False, False, "All"
      End If
      
 'This is the problem
      
      errSpot = "Refresh 6 Before"
      If frmScale.Visible And sr.CardNumber <> "" Then
         frmScale.Refresh
      End If
      errSpot = "Refresh 6 After"
            
            
   
   GoTo ExitSub
 
ExitSub:
   Exit Sub
StartError:
   Dim sDescription As String
   Dim sNumber As String
   
   sDescription = Err.Description
   sNumber = Err.Number
   MsgBox sDescription & " Subroutine: frmScale.FormActivate"
   WriteErrorToDB sDescription, sNumber, "frmScale", "FormActivate", IIf(sr.CardNumber = "", mCard & "-", sr.CardNumber), SCALE_ID, errSpot, sr.ProfileDescription
   GoTo ExitSub
 
End Sub

Open in new window

0
z3r3Commented:
Is sr a global variable?
0
Fraser_AdminAuthor Commented:
Public sr As clsScaleVariables

This is set on a module that gets executed when the program opens.  Then between each transaction I call a clear routine that just clears all the properties of it (ie. sr.cardnumber = "")
0
z3r3Commented:
Well then it seems as though the value is being cleared or reset unexpectedly!

If you could send me more it could be helpful do you have a mail address I can send you e-mail on?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fraser_AdminAuthor Commented:
juliesatwork@hotmail.com

i can send you the code for the entire frmScale.  Then you can see what is going on.  But what I don't understand is if it is being reset, why is it that it is still doing the refresh??
0
Fraser_AdminAuthor Commented:
issue seems to be due to objects not always getting terminated.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.