?
Solved

Debugging in VB when error only occurs in compiled program

Posted on 2003-03-04
15
Medium Priority
?
252 Views
Last Modified: 2010-08-05
I need some help with debugging a VB6 app.  How would be the best way to go about debugging when the error only occurs on certain computers (not the computer complied on).  Can not be duplicated inside of VB, i.e. only occurs in the program when its compiled.

Please help me!  I will reward everyone who helps with points! The code follows were the error is occuring.


    Dim found As Boolean
    Dim rsTemp As New ADODB.RecordSet
   
    rsTemp.Open "Select * from [PartsInv] where [InventoryNum]=" & Str$(rec.inventorynum), m_Connection, adOpenDynamic, adLockOptimistic
    found = Not rsTemp.EOF
    If found Then
        SaveRec rsTemp, rec
        'error occurs here "rsTemp.Update"
        rsTemp.Update
        Dim initialPosition, x2 As Integer
        initialPosition = m_Recordset.AbsolutePosition
        m_Recordset.Requery
        m_Recordset.Move initialPosition - 1
        x2 = m_Recordset.AbsolutePosition
    Else
        MsgBox ("Error Attempting to Update Non-Existant Part")
    End If
0
Comment
Question by:adamkushner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
15 Comments
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 8064895
Hi,

What run-time error do you get? If it's run-time error 5, and you call this piece of code directly after you have shown a form with vbModal, the msgbox yields the error. This is a bug in microsoft visual basic.

Your other question, how to debug it, either use profiler programs like NuMega DevPartner, or use msgbox to pinpoint it.

Grtz.©

D.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 8065021
i would be VERY surprised if the code runs ANYWHERE, as this line:

rsTemp.Open "Select * from [PartsInv] where [InventoryNum]=" & Str$(rec.inventorynum), m_Connection, adOpenDynamic, adLockOptimistic

indicates that InventoryNum is a TEXT field.  It should be code like this:

rsTemp.Open "Select * from [PartsInv] where [InventoryNum]='" & Str$(rec.inventorynum) & "'", m_Connection, adOpenDynamic, adLockOptimistic

now if InventoryNum is in fact a NUMBER field (INTEGER or LONG) then this line should be coded like this:

rsTemp.Open "Select * from [PartsInv] where [InventoryNum]=" & cInt(rec.inventorynum), m_Connection, adOpenDynamic, adLockOptimistic

or

rsTemp.Open "Select * from [PartsInv] where [InventoryNum]=" & cLng(rec.inventorynum), m_Connection, adOpenDynamic, adLockOptimistic

AW
0
 

Author Comment

by:adamkushner
ID: 8065022
No run time error, the program just terminates.

The error occurs here: rsTemp.Update
But I cannot figure out why, or why it only happens in the program once its compiled.

Yes, the error occurs in a form called with vbmodal.  Do you know of a fix? a way around?

Thanks for the quick answer!!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:adamkushner
ID: 8065111
Arthur_Wood,

InventoryNum is a text field, unfortunatly.

rsTemp.Open "Select * from [PartsInv] where [InventoryNum]= '" & Str$(rec.inventorynum) & "'", m_Connection, adOpenDynamic, adLockOptimistic

instead of

rsTemp.Open "Select * from [PartsInv] where [InventoryNum]=" & Str$(rec.inventorynum), m_Connection, adOpenDynamic, adLockOptimistic

results in a data type mismatch in criteria expression error. What's the reason for the added '" and "'"?
0
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 8065127
Arthur,

What is an SQL statement??? Right, text. Even if you explicitly convert it to a long, or an integer, VB does an Implicit conversion to a string datatype.

Your comment only applies when the field itself is indeed text. Then you need to use the ' (apastroph) to denote the value.

Adam, if you remove the message box saying the update is performed on a non-existing part, does the compiled version run on all clients?

If so, perform validation before the user closes the form. That way, you can prevent a message at the place you get it now, and saves some time in providing a way for the user to either correct the mistake, or cancel the whole proces.

If it doesn't, then you must look into it closer by putting messageboxes at various points in the code. If you locate the offending line, you can examine it closer.

Grtz.©

D.
0
 

Author Comment

by:adamkushner
ID: 8065185
No, sorry, The msg for the non-esisting part doesn't ever happen, it was more to trap an error during development.  So removing it, the error still occurs.  when the code (rsTemp.Update) is run the program unexpectedlly terminates.
0
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 8065265
Adam,

Your call to "SaveRec rsTemp, Rec"... Is the recordset argument passed ByRef?

Got any error handling itself in place? Might be ADO is giving problems that generate some error that isn't being displayed.

Also, you might want to check the MDAC installations on the clients your program fails.

Grtz.©

D.
0
 
LVL 3

Expert Comment

by:PNJ
ID: 8065463
You could try another way:

  Dim RSTemp as ADODB.Recordset, SQL as String
  Set RSTemp = New ADODB.Recordset

and try using SQL to do the update:

  m_connection.BeginTrans
  SQL = "UPDATE [PARTSINV] WHERE ....
  m_connection.Execute SQL
  m_connection.CommitTrans

I never use the .Update method. I only ever use "UPDATE..." & .Execute

I have no answer as to why this should work and why your way doesn't, but it may be worth investigating.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8065819
What does SaveRec do?

Can you provide the code?

mlmcc
0
 

Author Comment

by:adamkushner
ID: 8065869
Private Sub SaveRec(rs As ADODB.RecordSet, rec As clsParts)

rs.Fields("PartNumber1").Value = rec.PartNumber1
rs.Fields("PartNumber2").Value = rec.PartNumber2
rs.Fields("PartNumber3").Value = rec.PartNumber3
rs.Fields("BinNumber").Value = rec.BinNumber
rs.Fields("Description").Value = rec.Description
rs.Fields("Units").Value = rec.Units

End Sub
0
 

Author Comment

by:adamkushner
ID: 8065999
Private Sub SaveRec(rs As ADODB.RecordSet, rec As clsParts)

rs.Fields("PartNumber1").Value = rec.PartNumber1
rs.Fields("PartNumber2").Value = rec.PartNumber2
rs.Fields("PartNumber3").Value = rec.PartNumber3
rs.Fields("BinNumber").Value = rec.BinNumber
rs.Fields("Description").Value = rec.Description
rs.Fields("Units").Value = rec.Units

End Sub
0
 

Author Comment

by:adamkushner
ID: 8066519
Would anyone be willing to take a look at the code if I e-mail it to them?

I'm considering re-writing it to update using a different method but I have so much time it it I'd rather just get this sorted out. . .
0
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 8070120
Hi Adam,

Yes, i'll be willing to look into the full code, if it is still current.

Might want to send it to d.van.duijne@kobalt.nl. Could be you get a message that it's not delivered, but I can take it from the sweeper.

Grtz.©

D.
0
 

Author Comment

by:adamkushner
ID: 8071289
daffyduck14mil,

Thanks a lot for the offer.  I found the problem.  Inside of access I sorted the records by a value other than the key which is also an autonumber.  This was causing the bug.

Thanks to everyone for the help.

Points for daffyduck14mil: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20538231.html
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8114741
PAQ'd and points refunded

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

719 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