• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Debugging in VB when error only occurs in compiled program

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
adamkushner
Asked:
adamkushner
1 Solution
 
daffyduck14milCommented:
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
 
Arthur_WoodCommented:
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
 
adamkushnerAuthor Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
adamkushnerAuthor Commented:
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
 
daffyduck14milCommented:
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
 
adamkushnerAuthor Commented:
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
 
daffyduck14milCommented:
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
 
PNJCommented:
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
 
mlmccCommented:
What does SaveRec do?

Can you provide the code?

mlmcc
0
 
adamkushnerAuthor Commented:
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
 
adamkushnerAuthor Commented:
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
 
adamkushnerAuthor Commented:
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
 
daffyduck14milCommented:
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
 
adamkushnerAuthor Commented:
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
 
moduloCommented:
PAQ'd and points refunded

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now