PDA

View Full Version : Solved: Run Time Error 91



Slicemahn
08-30-2007, 07:34 AM
Hello Everyone!

I am trying to write lines from Excel spreadsheet into my Access table. I know that the code works because I have executed it many times before. When I step through the code I receive a run time error 91: Object variable or With Block variable not set. I haven't a clue of what this means. Does anyone have any ideas? My code is as follows:

Sub DataUpload()
Dim conn As ADODB.Connection
Dim rcdst As ADODB.Recordset
Dim Row As Long
With ActiveSheet
Set conn = New ADODB.Connection
' connect to the database
conn.Open "Provider=Microsoft.JET.OLEDB.4.0; " & _
"Data Source=S:\RSS\BU 03\RESP 7070\DEPT 210\NWFPlanning\BUDGET TRACKING REPORTS\Audrey Ling\NAT DIS\National Call DisconnectsDB.mdb;"

'Open a recordset
rcdst.Open "tblNationalCallDisconnects", conn, adOpenKeyset, adLockOptimistic, adCmdTable

Row = 6
' the start row in the worksheet
Do While Len(Range("A" & Row).Formula) > 0

' add to the recordset

With rcdst
.AddNew
.Fields("ReportDate") = Cells(2, 8).Value
.Fields("UniversalCallID") = Range("A" & Row).Value
.Fields("CallID") = Range("B" & Row).Value
.Fields("SegmentNumber") = Range("C" & Row).Value
.Fields("ACD") = Range("D" & Row).Value
.Fields("CMS") = Range("E" & Row).Value
.Fields("StartDate") = Range("F" & Row).Value
.Fields("StartTime") = Range("G" & Row).Value
.Fields("StopDate") = Range("H" & Row).Value
.Fields("StopTime") = Range("I" & Row).Value
.Fields("DOW") = Range("J" & Row).Value
.Fields("CallingParty") = Range("K" & Row).Value
.Fields("DialedNumber") = Range("L" & Row).Value
.Fields("FirstVDN") = Range("M" & Row).Value
.Fields("DispositionTime") = Range("N" & Row).Value
.Fields("AnsweringSplit") = Range("O" & Row).Value
.Fields("AvayaID") = Range("P" & Row).Value
.Fields("AnsweringLoginID") = Range("Q" & Row).Value
.Fields("Duration") = Range("R" & Row).Value
.Update
End With
Row = Row + 1

Loop
rcdst.Close
Set rcdst = Nothing
conn.Close
Set conn = Nothing
End With
End Sub

Many thanks for any help that you may provide.

malik641
08-30-2007, 08:11 AM
When you get the error, VBA should highlight the line it's getting the error at. Which line is getting highlighted?

And as a side note, you should get rid of
With ActiveSheet
'...
End With
Because you don't use it at all.

mvidas
08-30-2007, 08:15 AM
You are not creating your "rcdst" variable. Right above your "rcdst.Open" line, insert this:
Set rcdst = New ADODB.RecordSet

malik641
08-30-2007, 08:23 AM
Darn...missed that :doh:
Thanks Matt

mvidas
08-30-2007, 08:30 AM
Just gotta look for the object (http://www.vbaexpress.com/forum/showthread.php?t=14514)s and make sure they're being created or qualified correctly :)

malik641
08-30-2007, 08:35 AM
Just gotta look for the object (http://www.vbaexpress.com/forum/showthread.php?t=14514)s and make sure they're being created or qualified correctly :)
I think I helped answer their question :)

mvidas
08-30-2007, 09:19 AM
LOL. I keep thinking of things I'd love to add to it, but wont as they could be taken unprofessionally. :dunno Maybe I'm missing something..?

Bob Phillips
08-30-2007, 09:32 AM
LOL. I keep thinking of things I'd love to add to it, but wont as they could be taken unprofessionally. :dunno Maybe I'm missing something..?

Yeah, but what's an object?

malik641
08-30-2007, 09:36 AM
Yeah, but what's an object?
:rotlaugh::rotlaugh:


LOL. I keep thinking of things I'd love to add to it, but wont as they could be taken unprofessionally. :dunno Maybe I'm missing something..?
It doesn't matter. If you ask me, I think they are acting unprofessionally.

Anyway, I think we're going a bit off topic from Slicemahn's question. I hope he knows what an object is :)

Slicemahn
09-03-2007, 11:24 AM
Wow. I missed that too. Thanks malik