|
-
Sep 1st, 2010, 10:53 AM
#1
Thread Starter
New Member
[RESOLVED] Vb
Hello Everyone,
I getting this error message when I run the buge the cod.
Run-Time error -2147217887 (80040e21)
Multiple-step OLE DB operation
Here is the code, please take at it for me.
vb Code:
Public Function procUpdateQry_3a(sn$, rw%, bldgid$, leasid$, suitid$)
Dim rs, sqlstr$, conn As ADODB.Connection, ptbl$, tbl$, fld$, tdel%, ptbl2$, t%, tt%, nxttbl$, lsttbl$
Dim i%, ii%, endcol%
Dim sqlins1$, sqlins2$, addrec%
Dim ok%
'ptbl is first MRI table specified on sheet
'tbl--the MRI table ref from the current col is compared to this
'nxttbl is the col ref for the column with the next unmatching table (the next table to query)
'
Set rs = New ADODB.Recordset
rs.CursorType = adOpenStatic
rs.LockType = adLockPessimistic
Sheets(sn).Select
Set conn = OpenConnection()
If sn = "Lease Info" Then
Range("E" & Trim(Str(rw))).Activate
Else
Range("D" & Trim(Str(rw))).Activate
End If
ptbl = Left(Cells(4, ActiveCell.Offset(0, i).Column).Value, InStr(1, Cells(4, ActiveCell.Offset(0, i).Column), ".") - 1)
'If leasid = "003622" Then Stop
Debug.Print ptbl
If Range("BA" & Trim(Str(rw))).Value = "Del" Then
sqlstr = "DELETE FROM " & ptbl & " WHERE BLDGID='" & Trim(bldgid) & "' AND LEASID='" & Trim(leasid) & "'"
rs.Open sqlstr, conn
Else
endcol = False: addrec = False
Do While Not endcol
'At start of sheet ptbl contains first MRI Table ref
If ptbl = "SSQF" Then
sqlstr = "SELECT * FROM " & ptbl & " WHERE BLDGID='" & Trim(bldgid) & "' AND SUITID='" & Trim(suitid) & "' AND SQFTTYPE='" & Range("I" & Trim(Str(rw))) & "' AND EFFDATE='" & Range("AE" & Trim(Str(rw))) & "'"
Else
sqlstr = "SELECT * FROM " & ptbl & " WHERE BLDGID='" & Trim(bldgid) & "' AND LEASID='" & Trim(leasid) & "'"
End If
rs.Open sqlstr, conn
If rs.BOF And rs.EOF Then
''record count=0 therefore data for this table must be inserted...
'sqlins1 = "INSERT INTO " & ptbl & "(BLDGID, LEASID, "
'sqlins2 = " VALUES('" & Trim(bldgid) & "','" & Trim(leasid) & "'"
'create insert query
'find next tableref
'set ptbl, ii
' Stop
'Exit Do
ok = True
If UCase(ptbl) = "CPII" Then
If Len(Trim(Range("D" & Trim(Str(rw))))) = 0 Then
ok = False
End If
End If
If UCase(ptbl) = "PTWI" Then
If Len(Trim(Range("P" & Trim(Str(rw))))) = 0 Then
ok = False
End If
End If
If ok Then
rs.AddNew
addrec% = True
rs("bldgid") = bldgid
If UCase(ptbl) <> "SSQF" Then
rs("leasid") = leasid
'rs("sqfttype") = Trim(Range("I" & Trim(Str(rw))))
End If
If UCase(ptbl) = "SSQF" Then
rs("sqfttype") = Trim(Range("I" & Trim(Str(rw))))
End If
If UCase(ptbl) = "LATERMS" Or UCase(ptbl) = "LATERMS2" Or UCase(ptbl) = "LATERMS3" Or Left(UCase(ptbl), 2) = "LA" Or UCase(ptbl) = "SSQF" Then
rs("suitid") = suitid
End If
If UCase(ptbl) = "SSQF" Then
(I get the error here) rs("effdate") = Range("AE" & Trim(Str(rw)))
End If
Else
Exit Function
End If
End If
Last edited by Hack; Sep 1st, 2010 at 10:59 AM.
Reason: Added Highlight Tags
-
Sep 1st, 2010, 10:12 PM
#2
Re: Vb
is effdate a date field?
you may need to convert the content of the cell to a suitable value or string
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 1st, 2010, 11:53 PM
#3
Addicted Member
Re: Vb
Hi,
Change that line to :
Code:
If Trim(Range("AE" & Trim(Str(rw)))) <> "" Then
If IsDate(Range("AE" & Trim(Str(rw)))) Then
rs("effdate") = CDate(Range("AE" & Trim(Str(rw))))
End If
End If
Regards
Veena
-
Sep 2nd, 2010, 08:00 AM
#4
Re: Vb
a thread entitled vb is very vague try using proper titles so that members can find your thread much easier when the search for it
VB.NET MVP 2008 - Present
-
Sep 2nd, 2010, 08:54 AM
#5
Re: Vb
and it would have helped to note what line gives the error... clearly there seems to be a number of things potentially wrong as we've all noted something different.
Lines 31/32 ... that's not the way to run an action query... Look up the ADO.Command object...
-tg
-
Sep 2nd, 2010, 03:03 PM
#6
Thread Starter
New Member
Re: Vb
 Originally Posted by VeenaMG
Hi,
Change that line to :
Code:
If Trim(Range("AE" & Trim(Str(rw)))) <> "" Then
If IsDate(Range("AE" & Trim(Str(rw)))) Then
rs("effdate") = CDate(Range("AE" & Trim(Str(rw))))
End If
End If
Regards
Veena
Thank you for your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|