borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (User Login/Password Checking)Next Topic (Run-time error 91) New Topic New Poll Post Reply
AndreaVB Forum : Database : VB and Excel
Poster Message
inna
Level: Guest


icon VB and Excel

Can somebody help
I have wrote the code for reading Excel.
It's load array with value from Excel.
But not all data can load. It's give the error
"Invalid use of null"

for example:
1234
2345
M234 - this record will have the error
3456

Thanks a lot

if you put checking for null
it's will skip the record "M234"
but it's there.
Because if you open Excel not lilke object
than it's will work. But it's work very long time, if you have more than 60000record it's will run for whole day.

HELP HELP

code below

  


Dim sheetname1, FilePath1 As String
Dim cn1 As Object
Dim rs1 As Object
Dim sConn1 As String

'On Error GoTo EH
DoEvents

FilePath1 = "C:Mikecc_labor_updN.xls"
sheetname1 = "Sheet1"
sConn1 = "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" & FilePath1

Set cn1 = CreateObject("ADODB.Connection")
Set rs1 = CreateObject("ADODB.Recordset")

cn1.ConnectionString = sConn1
cn1.Open

rs1.Source = "SELECT * FROM [" & sheetname1 & "$]" '& sql
rs1.Open , cn1, , adCmdText

Dim ws As Object

numarr = 0
'rs.MoveFirst
rs1.MoveFirst
Do Until rs1.EOF
    numarr = numarr + 1
    ReDim Preserve arrJob(numarr)

    If not IsNull(rs1.Fields(0).Value) Then
        arrJob(numarr).ijobNum = rs1.Fields(0).Value
    End if

    
    Debug.Print rs1.Fields(0)
rs1.MoveNext
Loop
    
rs1.Close
cn1.Close

            

[Edited by inna on 13-12-2002 at 04:05 PM GMT]

13-12-2002 at 03:45 AM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon Re: VB and Excel

The error means the contents of the current field is NULL.

If you change it to:


    If not IsNull(rs1.Fields(0).Value) Then
        arrJob(numarr).ijobNum = rs1.Fields(0).Value
    End if


It shouldn't error.

13-12-2002 at 04:23 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
inna
Level: Guest

icon Re: Re: VB and Excel

quote:
JLRodgers wrote:
The error means the contents of the current field is NULL.

If you change it to:


    If not IsNull(rs1.Fields(0).Value) Then
        arrJob(numarr).ijobNum = rs1.Fields(0).Value
    End if


It shouldn't error.



I already have checking for isnull.
It's just work this way:
if the 1st record start from number until met
with string than give the error
if it's start from string and met witn number
than give the error
13-12-2002 at 02:32 PM
| Quote Reply
MohamedAnwar
Level: Guest

icon Re: VB and Excel

Hi
I think the problem that happend to u due to one of two things cause the records u give it the example which error happended have letters other than contain only numbers was pass in right way.
1- your Sql statment may be
2- your object that u use to load the array configured to read only numbers no Strings.

i am not sure but could be

Mohamed

04-03-2003 at 11:28 AM
| Quote Reply
AndreaVB Forum : Database : VB and Excel
Previous Topic (User Login/Password Checking)Next Topic (Run-time error 91) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder