|
-
Jun 23rd, 2006, 12:00 PM
#1
Thread Starter
Addicted Member
populating a combo box in vbscript
hi all,
im not too good with the vbscript. i am trying to populate a combo box using a sql query. here is the code that i have
VB Code:
dim cDB
dim oRec
set cDB = Session.AppDatabase
Set oRec = cDB.OpenRecordset("Select distinct dbo.vluCustomerAddrBilling.AddrName, dbo.tPA00175.chrJobName FROM dbo.vluCustomerAddrBilling INNER JOIN dbo.tPA00175 ON dbo.vluCustomerAddrBilling.CustKey = dbo.tPA00175.CustKey WHERE (dbo.tPA00175.chrJobName = '"&Form.Controls("txtProjectName")&"')",1,0)
Do Until oRec.EOF
combobox1.AddItem oRec("AddrName")
oRec.MoveNext
Loop
oRec.Close
i am getting the error message with the oRec.EOF. this is the way to do it in vb6 but what is the syntax for vb script.
thanks alot
tibor
-
Jun 23rd, 2006, 12:43 PM
#2
Thread Starter
Addicted Member
Re: populating a combo box in vbscript
i get this error
object doesnt support this property or method: 'oRec.eof'
-
Jun 23rd, 2006, 01:33 PM
#3
Thread Starter
Addicted Member
Re: populating a combo box in vbscript
ok i figured out the loop issue but now im getting a not so major error, its more of an annoyance.
here is the code that resolved my eof problem
VB Code:
Do Until EOF=true
Form.Controls("ComboBox1").AddItem oRec.Field("AddrName")
oRec.MoveNext
Loop
oRec.Close
ok now i have an error message popping up saying
Attempt to scroll past end or before beginning of data.
the loop works but it adds the last value twice as i would imagine thats why i get the message. so what is it that is causing it to do this??
tibor
-
Jun 23rd, 2006, 04:40 PM
#4
Fanatic Member
Re: populating a combo box in vbscript
Tibor,
Try this -
VB Code:
If Not oRec.BOF And Not oRec.EOF Then
Do While Not oRec.EOF
combobox1.AddItem oRec("AddrName")
oRec.MoveNext
Loop
End If
oRec.Close
-
Jun 23rd, 2006, 05:11 PM
#5
Thread Starter
Addicted Member
Re: populating a combo box in vbscript
still gives me the same error.
-
Jun 24th, 2006, 05:36 AM
#6
Fanatic Member
Re: populating a combo box in vbscript
Try opening your recordset like this -
VB Code:
Dim sSQL
Dim cn
Dim cnStr
Dim oRec
cnStr="driver={SQL Server};server=SERVER_NAME; database=DB_NAME"
Set cn=Server.CreateObject("ADODB.Connection")
cn.open cnStr
sSQL="Select distinct dbo.vluCustomerAddrBilling.AddrName, dbo.tPA00175.chrJobName" & _
" FROM dbo.vluCustomerAddrBilling INNER JOIN dbo.tPA00175 ON dbo.vluCustomerAddrBilling.CustKey = dbo.tPA00175.CustKey" & _
" WHERE (dbo.tPA00175.chrJobName = '" & Form.Controls("txtProjectName") & "')"
Set oRec=cn.execute(sSQL)
If Not oRec.BOF And Not oRec.EOF Then
Do While Not oRec.EOF
combobox1.AddItem oRec("AddrName")
oRec.MoveNext
Loop
End If
oRec.Close
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
|