Login | |
|
 |
Re: Populate combobox from Access db - 6/30/2005 3:01:54 AM
|
|
 |
|
| |
NigeJK
Posts: 16
Score: 0
Joined: 6/27/2005
From:
Status: offline
|
Many thanks... I implemented the extra code, changed doActivity() and set sFspec & strsql to the correct versions. I loaded the page into IE and when I clicked the button I get the "Connection" error. I have had a look through but cannot see any problems. I have put my code here. Any ideas ? <html> <head> <title>Activity</title> <meta http-equiv = "content-script-type" content = "text/vbscript"/> <script language = "VBScript" type = "text/vbscript" > '<![CDATA[ Sub doActivity() Dim aValues Dim oCBX aValues = Array( "one", "two", "three" ) Set oCBX = document.All( "id_cbxActivity" ) ' fillCBX oCBX, aValues fillDbCBX oCBX End Sub Sub fillCBX( oCBX, aValues ) Dim oDoc Dim sValue Dim oOpt oCBX.Length = 0 Set oDoc = oCBX.document For Each sValue In aValues Set oOpt = oDoc.createElement( "OPTION" ) oOpt.Text = sValue oOpt.Value = sValue oCBX.Options.Add oOpt Next End Sub Sub fillDbCBX( oCBX ) Dim oDoc Dim sValue Dim oOpt Dim sFSpec Dim strsql ' as string Dim conn ' as ADODB.Connection Dim rs ' As ADODB.Recordset Dim sTmp sFSpec = "C:\BMD\eDatabase.mdb" strsql = "SELECT DISTINCT Activity.Activity FROM Activity" ' sFSpec = "C:\wis\_vbs\0506\dev\forum\activ.mdb" ' strsql = "SELECT DISTINCT sActivity FROM Activity" On Error Resume Next Set conn = getCnMDB( sFSpec ) If conn Is Nothing Then MsgBox "Connection" : Exit Sub End If Set rs = GetSelectFRO( conn, strsql ) If rs Is Nothing Then MsgBox "Recordset": Exit Sub End If On Error Goto 0 oCBX.Length = 0 Set oDoc = oCBX.document Do While Not rs.EOF Set oOpt = oDoc.createElement( "OPTION" ) sTmp = getFieldValueString( rs, "sActivity" ) oOpt.Text = sTmp oOpt.Value = sTmp oCBX.Options.Add oOpt rs.MoveNext Loop rs.Close conn.Close End Sub Function getFieldValueString( oRS, sNaNu ) Dim sRVal sRVal = oRS.Fields( sNaNu ) If IsNull( sRVal ) Then sRVal = "" End If getFieldValueString = CStr( sRVal ) End Function Function getCnMDB( sFSpec ) Dim oCN Dim sTmp sTmp = "Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Persist Security Info=False;" _ & "Data Source=" & sFSpec & ";" On Error Resume Next Set oCN = CreateObject( "ADODB.Connection" ) oCN.Open sTmp If 0 <> Err.Number Then stop Set oCN = Nothing End If On Error GoTo 0 Set getCnMDB = oCN End Function Function getSelectFRO( oCN, sSQL ) Const adOpenForwardOnly = 0 ' 00000000 Const adLockReadOnly = 1 ' 00000001 Const adCmdText = 1 ' 00000001 Dim oRS On Error Resume Next Set oRS = CreateObject( "ADODB.Recordset" ) oRS.Open sSQL, oCN, adOpenForwardOnly, adLockReadOnly, adCmdText If 0 <> Err.Number Then Set oRS = Nothing End If On Error GoTo 0 Set getSelectFRO = oRS End Function ']]> </script> </head> <body> <form id = "frnActivity"> <input type = "BUTTON" onclick = "doActivity()" value = "Activity!"> <select id = "id_cbxActivity" size = "1" ></select> </form> </body> </html>
|
|
| |
|
|
|
|
|