Re: Troubleshooting error in VB 6.0

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"WB" <none> wrote in message news:eWx4oDDCHHA.3380@xxxxxxxxxxxxxxxxxxxxxxx
I have an application designed in VB6.0. I am being told from users (away
from development office) that an error is being generated (error 94). I
placed some logging code in the application to write test lines out to a
text file so I can pinpoint exactly why and where the error is happening.
The problem is the error being generated doesn't occur or match the test
lines being written to the text file. I am trying to get answer to this
question.

Error number 94 is Invalid use of Null. Chances are, you're reading data from a database into a recordset, and when going through the recordset, you're attempting to assign the field's value to a string variable or perhaps a textbox (or anything that can only accept a string).

If the data type of the FIELD is a string type, one common way of dealing with the possibility of it being null is just concatenating a 0-length string (or you can preprend it as well). Like this:

sData = oRS.Fields("MyField").Value & ""

Alternatively, use the IsNull function to check it:

If IsNull(oRS.Fields("MyField").Value Then
sData = ""
Else
sData = oRS.Fields("MyField").Value
End If

You have to use IsNull for non-string types. For example, this WON'T work:

Dim lData As Long
lData = oRS.Fields("MyField").Value & ""

(You'll get the invalid use of Null error)


Is it possible for lines of code to execute without a resume next
or any other "trapping", and the error to display after several lines have
executed beyond the actual error?

Not sure I understand the question entirely, but I guess the answer would be yes. Among others, one way you could have this situation is if you call a function that doesn't have it's own local error from a procedure which DOES have a local and active error handler. Just for an extremely simple (and admittedly poor) example:

Option Explicit

Private Sub ShowRemainder(ByVal Divisor As Long, ByVal Dividend As Long)

Dim lRemainder As Long

lRemainder = Divisor Mod Dividend
MsgBox lRemainder

End Sub

Private Sub Form_Click()

On Error GoTo EH

ShowRemainder 10, 0


'just some code that won't ever execute unless the above line is changed
'such that 0 is not passed for the Dividend parameter.
Me.Move 500, 500

EH:

MsgBox Err.Description

End Sub

(Hmm, looking at that, did I get Divisor and Dividend right? Divisor is the number "on top", right? <g>)

--
Mike
Microsoft MVP Visual Basic

.



Relevant Pages

  • Re: Troubleshooting error in VB 6.0
    ... I do understand the error 94 and the reason it is being thrown. ... perhaps a textbox (or anything that can only accept a string). ... Private Sub ShowRemainder(ByVal Divisor As Long, ...
    (microsoft.public.vb.general.discussion)
  • Re: Trim() function chain-link. Please Help me...
    ... Private Sub CommandButton1_Click ... Dim Divisor As Long ... Dim Pwd As String ... 'Tell the workers to not leave these 2 options blank ...
    (microsoft.public.excel.programming)
  • Re: Playing AVI and MPEG using MCI
    ... "mciSendStringA" (ByVal lpstrCommand As String, ... Dim mlRet As Long ... Private Sub CenterObject ... If mlRet 0 Then ...
    (microsoft.public.vb.controls)
  • RE: Adding Bound Pictures to an Access Database
    ... when the student's picture is missing it is leaving the ... Private Sub Form_Current ... Dim strPath As String ... Private Function pfValidFile(aFile As String) As Boolean ...
    (microsoft.public.access.modulesdaovba)
  • RE: jpgs not showing on forms
    ... Rather than embed the pictures in the database store the paths to the JPEG ... Private Sub cmdAddImage_Click ... Dim strAdditionalTypes As String, strFileList As String ... Private Sub cmdDeleteImage_Click ...
    (microsoft.public.access.gettingstarted)