G
Guest
I am getting a error when I open this recordset. I have tested the sql statement in winsql lite it worked fine. I just keep getting this error "-2147217908","Command text was not set for the command object.","Microsoft OLE DB Provider for ODBC Drivers" everytime it trys to open the recordset.. Below is part of my code.. Thansk for the help..
'Dimmension
Dim I As Intege
Dim conSQL As ADODB.Connectio
Dim rsSQL As ADODB.Recordse
Dim strSQL As Strin
Dim strDateFrom As Strin
Dim strDateTo As Strin
Dim strLineNumber As Strin
Dim blnStartup As Boolea
Dim strDefect(100, 1) As Strin
On Error GoTo errhandle
strDateFrom = Sheets("start(1)").txtFirstdate.Text & Space(1) & "00:00:01 AM'
strDateTo = Sheets("start(1)").txtSecondDate.Text & Space(1) & "11:59:59 PM'
strLineNumber = Sheets("start(1)").Range("c5").Valu
'Builds the sql Statemen
strbuild = "select " &
"DATEDIFF(MINUTE,startdatetime,enddatetime) as Timeused " &
",tblexistingrollcut.rollnumber, " &
"tblexistingrollcut.cutname,dispositioncode,rollcutdefect from " &
" tblroll,tblexistingrollcut left outer join tblrollcutdefect " &
" on tblexistingrollcut.rollnumber = tblrollcutdefect.rollnumber AND " &
" tblexistingrollcut.cutname = tblrollcutdefect.cutname " &
" where tblroll.rollnumber = tblexistingrollcut.rollnumber AND " &
" linenumber = '" & strLineNumber & "' and " &
" startdatetime > '" & strDateFrom & " AND " &
" ENDDATETIME < '" & strDateT
MsgBox strbuil
'''''''''''''''''''''''''''''''''''''''''''''''''
'Creates the connection to the databas
Set conSQL = New ADODB.Connectio
Set rsSQL = New ADODB.Recordse
''''''''''''''''''Connecting to Production''''''''''
If conSQL.State = adStateOpen The
conSQL.Clos
End I
Application.StatusBar = "(Connecting) to Production server
'on the fly connectio
conSQL.Open "Driver={sql server};server=production;database=dbsims;UID=test;pwd=test
'''''''Pulling Defect % '''''''''''''''''''''''''''''
Application.StatusBar = "(Connected Pulling Defect % from production server
'rsSQL.Open "select * from tblroll", conSQL, adOpenForwardOnly, adLockReadOnl
rsSQL.Open strSQL, conSQL, adOpenForwardOnly, adLockReadOnly
'Dimmension
Dim I As Intege
Dim conSQL As ADODB.Connectio
Dim rsSQL As ADODB.Recordse
Dim strSQL As Strin
Dim strDateFrom As Strin
Dim strDateTo As Strin
Dim strLineNumber As Strin
Dim blnStartup As Boolea
Dim strDefect(100, 1) As Strin
On Error GoTo errhandle
strDateFrom = Sheets("start(1)").txtFirstdate.Text & Space(1) & "00:00:01 AM'
strDateTo = Sheets("start(1)").txtSecondDate.Text & Space(1) & "11:59:59 PM'
strLineNumber = Sheets("start(1)").Range("c5").Valu
'Builds the sql Statemen
strbuild = "select " &
"DATEDIFF(MINUTE,startdatetime,enddatetime) as Timeused " &
",tblexistingrollcut.rollnumber, " &
"tblexistingrollcut.cutname,dispositioncode,rollcutdefect from " &
" tblroll,tblexistingrollcut left outer join tblrollcutdefect " &
" on tblexistingrollcut.rollnumber = tblrollcutdefect.rollnumber AND " &
" tblexistingrollcut.cutname = tblrollcutdefect.cutname " &
" where tblroll.rollnumber = tblexistingrollcut.rollnumber AND " &
" linenumber = '" & strLineNumber & "' and " &
" startdatetime > '" & strDateFrom & " AND " &
" ENDDATETIME < '" & strDateT
MsgBox strbuil
'''''''''''''''''''''''''''''''''''''''''''''''''
'Creates the connection to the databas
Set conSQL = New ADODB.Connectio
Set rsSQL = New ADODB.Recordse
''''''''''''''''''Connecting to Production''''''''''
If conSQL.State = adStateOpen The
conSQL.Clos
End I
Application.StatusBar = "(Connecting) to Production server
'on the fly connectio
conSQL.Open "Driver={sql server};server=production;database=dbsims;UID=test;pwd=test
'''''''Pulling Defect % '''''''''''''''''''''''''''''
Application.StatusBar = "(Connected Pulling Defect % from production server
'rsSQL.Open "select * from tblroll", conSQL, adOpenForwardOnly, adLockReadOnl
rsSQL.Open strSQL, conSQL, adOpenForwardOnly, adLockReadOnly