DViking
04-19-2004, 09:11 AM
Hi,
I hope somebody can help me with this one. I want to enter some data in an Access 2000 database through a webpage. On this page I have a listbox that I fill dynamically with some data of the database. I have written a bit of code which does the trick, but when I try to send the data from the form back to (another table) in the database, the value of this dynamically created listbox is NULL, no matter what I select in the list.
My code:
---------------
Dim dbConn As New ADODB.Connection
Dim cmdCommand As New ADODB.Command
Dim rstRecordSet As New ADODB.Recordset
Dim arr_nameMyTable() As String
Dim i, totMyTable As Integer
Dim htmlCode As String
Dim divMyTable As HTMLDivElement
dbConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
localPath & databaseSource & ";Mode=Read|Write"
dbConn.CursorLocation = adUseClient
dbConn.open
With cmdCommand
.ActiveConnection = dbConn
.CommandText = "SELECT * FROM MyTable;"
.CommandType = adCmdText
End With
With rstRecordSet
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.open cmdCommand
End With
totGUI = rstRecordSet.RecordCount
ReDim arr_idMyTable(totMyTable)
ReDim arr_nameMyTable(totMyTable)
rstRecordSet.MoveFirst
i = 1
htmlCode = "<P>GUI: <SELECT id=lstMyTable name=lstMyTable size=1>" + vbNewLine
htmlCode = htmlCode + "<OPTION value='' selected>Choose</OPTION>" + vbNewLine
With rstRecordSet
Do Until .EOF
arr_nameMyTable(i) = .Fields.Item("nameMyTable").Value
.MoveNext
htmlCode = htmlCode + "<OPTION value='" & arr_idMyTable(i) & "'>" & _
arr_nameMyTable(i) & "</OPTION>" + vbNewLine
i = i + 1
Loop
End With
htmlCode = htmlCode + "</SELECT></P>" + vbNewLine
Set divMyTable = Document.All("divMyTable")
If divMyTable Is Nothing Then
Document.body.insertAdjacentHTML "BeforeEnd", "<DIV><HR SIZE=2></DIV>"
Document.body.insertAdjacentHTML "BeforeEnd", "<DIV id=divMyTable>"
Document.body.insertAdjacentHTML "BeforeEnd", htmlCode
Document.body.insertAdjacentHTML "BeforeEnd", "</DIV>"
Else
divMyTable.innerHTML = htmlCode
End If
rstRecordSet.Close
dbConn.Close
Set dbConn = Nothing
Set rstRecordSet = Nothing
----------
When I submit the form on the webpage I get the error:
Field 'MyTable.nameMyTable' cannot be a zero-length string
HELP!
I hope somebody can help me with this one. I want to enter some data in an Access 2000 database through a webpage. On this page I have a listbox that I fill dynamically with some data of the database. I have written a bit of code which does the trick, but when I try to send the data from the form back to (another table) in the database, the value of this dynamically created listbox is NULL, no matter what I select in the list.
My code:
---------------
Dim dbConn As New ADODB.Connection
Dim cmdCommand As New ADODB.Command
Dim rstRecordSet As New ADODB.Recordset
Dim arr_nameMyTable() As String
Dim i, totMyTable As Integer
Dim htmlCode As String
Dim divMyTable As HTMLDivElement
dbConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
localPath & databaseSource & ";Mode=Read|Write"
dbConn.CursorLocation = adUseClient
dbConn.open
With cmdCommand
.ActiveConnection = dbConn
.CommandText = "SELECT * FROM MyTable;"
.CommandType = adCmdText
End With
With rstRecordSet
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.open cmdCommand
End With
totGUI = rstRecordSet.RecordCount
ReDim arr_idMyTable(totMyTable)
ReDim arr_nameMyTable(totMyTable)
rstRecordSet.MoveFirst
i = 1
htmlCode = "<P>GUI: <SELECT id=lstMyTable name=lstMyTable size=1>" + vbNewLine
htmlCode = htmlCode + "<OPTION value='' selected>Choose</OPTION>" + vbNewLine
With rstRecordSet
Do Until .EOF
arr_nameMyTable(i) = .Fields.Item("nameMyTable").Value
.MoveNext
htmlCode = htmlCode + "<OPTION value='" & arr_idMyTable(i) & "'>" & _
arr_nameMyTable(i) & "</OPTION>" + vbNewLine
i = i + 1
Loop
End With
htmlCode = htmlCode + "</SELECT></P>" + vbNewLine
Set divMyTable = Document.All("divMyTable")
If divMyTable Is Nothing Then
Document.body.insertAdjacentHTML "BeforeEnd", "<DIV><HR SIZE=2></DIV>"
Document.body.insertAdjacentHTML "BeforeEnd", "<DIV id=divMyTable>"
Document.body.insertAdjacentHTML "BeforeEnd", htmlCode
Document.body.insertAdjacentHTML "BeforeEnd", "</DIV>"
Else
divMyTable.innerHTML = htmlCode
End If
rstRecordSet.Close
dbConn.Close
Set dbConn = Nothing
Set rstRecordSet = Nothing
----------
When I submit the form on the webpage I get the error:
Field 'MyTable.nameMyTable' cannot be a zero-length string
HELP!