Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-Time Error 94 will not trap

Status
Not open for further replies.

usakjw

Programmer
Sep 8, 2005
47
US
I am writing a program that takes entries out of a Access Table reformats it and puts it into a word document. I actually have two questions the first,

Can I do something along these lines to set up an array?
INTArray = FRMVoterInfo.ADOVoterInfo.Recordset.RecordCount
Dim STRAddress(INTArray) as String

I currently have the array bing intitialized at 10000 however I know I only need around 6300. However In the future I may need less and I also may need more

Also at one point the program breaks with a Run-Time error of 94 Illegal use of Null.

I have set up a error handler Which is
On Error GoTo ErrorHandler:

LoopEnd:

INTCount = 1 + INTCount


FRMVoterInfo.ADOVoterInfo.Recordset.MoveNext

Else
INTCount = 1 + INTCount

FRMVoterInfo.ADOVoterInfo.Recordset.MoveNext

End If

Loop

Case 94 'Illegal Use of Null
BLNBreak = True
GoTo LoopEnd

I have only posted the cod that directly relates to the error and the error handler. The fields that are being read in from the Access Table are what the error is refering to.

If you need the entire code posted I will do that.

KJW
 
Try something like this:
[tt]
Private Sub Foo(ByVal Bar As Integer)
On Error GoTo Whatever

Bar = Bar + 1

Exit Sub

Whatever:
Select Case Err.Number
Case 94
MsgBox "OMG Error 94!!!1!one11eleven", vbCritical, "Bad News"
Case 5
MsgBox "Yo, Err 5"
Case Else
'bubble error up
Err.Raise Err.Number, "Sub Foo -> " & Err.Source, Err.Description
End Select
End Sub
[/tt]
 
Well except that sub wont actually change the value of Bar unless it is passed ByRef instead of ByVal ... but thats not really the point of the example.
 
Unless you need all the entries at the same time, I would recommend not using the array and just reformat the entries as they are read from the recordset. Also, use the recordset's EOF property to see if you went past the end. So it should look something like

Code:
'get recordset
With FRMVoterInfo.ADOVoterInfo.Recordset
  'go through the records
  Do While Not (.EOF)
     'process the contents by sub
     ProcessContents !MyField1, !MyField2
     'move on
     .MoveNext
  Loop
End With

-Max
 
I got it to work. It was the last record that is alway empty all the way across. I just used an if then else statement.

Thanks any way


KJW
 
Incidentally, for future reference, if you want to re-dimension an array, You can declare it and re-dimension it like this:

Code:
Dim x() as String
.
.
.
ReDim x(20) as String  ' this clears the data already in the array
. 
.
.
ReDim Preserve x(30)  ' This preserves any existing Data
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top