Results 1 to 6 of 6

Thread: populating a combo box in vbscript

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    245

    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:
    1. dim cDB
    2. dim oRec
    3.  
    4.  
    5.  
    6. set cDB = Session.AppDatabase
    7. 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)
    8.  
    9. Do Until oRec.EOF
    10.      combobox1.AddItem oRec("AddrName")
    11.      oRec.MoveNext
    12.      Loop
    13.      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

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    245

    Re: populating a combo box in vbscript

    i get this error

    object doesnt support this property or method: 'oRec.eof'

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    245

    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:
    1. Do Until EOF=true
    2.      Form.Controls("ComboBox1").AddItem oRec.Field("AddrName")
    3.      oRec.MoveNext
    4.      Loop
    5.      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

  4. #4
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Re: populating a combo box in vbscript

    Tibor,

    Try this -
    VB Code:
    1. If Not oRec.BOF And Not oRec.EOF Then
    2.   Do While Not oRec.EOF
    3.      combobox1.AddItem oRec("AddrName")
    4.      oRec.MoveNext
    5.   Loop
    6. End If
    7. oRec.Close

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    245

    Re: populating a combo box in vbscript

    still gives me the same error.

  6. #6
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Re: populating a combo box in vbscript

    Try opening your recordset like this -

    VB Code:
    1. Dim sSQL
    2. Dim cn
    3. Dim cnStr
    4. Dim oRec
    5.  
    6. cnStr="driver={SQL Server};server=SERVER_NAME; database=DB_NAME"
    7.  
    8. Set cn=Server.CreateObject("ADODB.Connection")
    9. cn.open cnStr
    10.  
    11. sSQL="Select distinct dbo.vluCustomerAddrBilling.AddrName, dbo.tPA00175.chrJobName" & _
    12.     " FROM dbo.vluCustomerAddrBilling INNER JOIN dbo.tPA00175 ON dbo.vluCustomerAddrBilling.CustKey = dbo.tPA00175.CustKey" & _
    13.     " WHERE (dbo.tPA00175.chrJobName = '" & Form.Controls("txtProjectName") & "')"
    14.  
    15. Set oRec=cn.execute(sSQL)
    16.  
    17. If Not oRec.BOF And Not oRec.EOF Then
    18.   Do While Not oRec.EOF
    19.      combobox1.AddItem oRec("AddrName")
    20.      oRec.MoveNext
    21.   Loop
    22. End If
    23. 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
  •  



Click Here to Expand Forum to Full Width