?
Solved

Unexpected Error

Posted on 2008-02-12
17
Medium Priority
?
436 Views
Last Modified: 2008-03-06
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?
0
Comment
Question by:Fraser_Admin
  • 9
  • 8
17 Comments
 
LVL 2

Expert Comment

by:z3r3
ID: 20875738
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
 

Author Comment

by:Fraser_Admin
ID: 20876045
how would i do that?  if frmB.visible then....
0
 
LVL 2

Expert Comment

by:z3r3
ID: 20877790
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:Fraser_Admin
ID: 20883704
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
 
LVL 2

Expert Comment

by:z3r3
ID: 20884055
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
 

Author Comment

by:Fraser_Admin
ID: 20884755
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
 
LVL 2

Expert Comment

by:z3r3
ID: 20885045
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
 

Author Comment

by:Fraser_Admin
ID: 20886001
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
 
LVL 2

Expert Comment

by:z3r3
ID: 20888031
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
 

Author Comment

by:Fraser_Admin
ID: 20898142
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
 
LVL 2

Expert Comment

by:z3r3
ID: 20900164
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
 

Author Comment

by:Fraser_Admin
ID: 20907569
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
 
LVL 2

Expert Comment

by:z3r3
ID: 20913711
Is sr a global variable?
0
 

Author Comment

by:Fraser_Admin
ID: 20913898
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
 
LVL 2

Accepted Solution

by:
z3r3 earned 2000 total points
ID: 20922977
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
 

Author Comment

by:Fraser_Admin
ID: 20923693
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
 

Author Comment

by:Fraser_Admin
ID: 20986657
issue seems to be due to objects not always getting terminated.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
In this article, we will show how to detach and attach a database and then show how to repair a corrupt database and attach it, If it has some errors. We will show how to detach and attach using SSMS or using T-SQL sentences.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question