marle35
Programmer
- Jul 17, 2007
- 36
I have followed the instructions in Microsoft's page to do the equivalent of a lookup function. When I do a Document.All.Item("ControlName").Value = "somehardcodedvalue" assignment in the Current event, it works just fine. When I try, like in those instructions, to access a value all ready in one of the controls (like in a select statement to open up a recordset) it gives an "unknown run-time error." I am using banded pages (all records showing one one page). My code looks like this:
Dim rst
Dim strSQL
Set rst = CreateObject("ADODB.Recordset")
strSQL = "SELECT tblHistory.OrderID, tblHistory.Comment, " & _
"tblHistory.EntryTime FROM tblHistory " & _
"WHERE tblHistory.OrderID = '" & _
Document.All.Item("txtOrderID").Value & _
"' ORDER BY tblHistory.EntryTime DESC;"
rst.Open strSQL, MSODSC.Connection
If Not rst.EOF Then
Document.All.Item("txtComment1").Value = Rst("Comment").Value
Document.All.Item("txtTime1").Value = Rst("EntryTime").Value
rst.MoveNext
If Not rst.EOF Then
Document.All.Item("txtComment2").Value = Rst("Comment").Value
Document.All.Item("txtTime2").Value = Rst("EntryTime").Value
End If
End If
rst.Close
The run-time error occurs at the rst open command. When I debug it, the strSQL does not contain any value for where Document.All.Item("txtOrderID").Value should be. Any ideas?
Dim rst
Dim strSQL
Set rst = CreateObject("ADODB.Recordset")
strSQL = "SELECT tblHistory.OrderID, tblHistory.Comment, " & _
"tblHistory.EntryTime FROM tblHistory " & _
"WHERE tblHistory.OrderID = '" & _
Document.All.Item("txtOrderID").Value & _
"' ORDER BY tblHistory.EntryTime DESC;"
rst.Open strSQL, MSODSC.Connection
If Not rst.EOF Then
Document.All.Item("txtComment1").Value = Rst("Comment").Value
Document.All.Item("txtTime1").Value = Rst("EntryTime").Value
rst.MoveNext
If Not rst.EOF Then
Document.All.Item("txtComment2").Value = Rst("Comment").Value
Document.All.Item("txtTime2").Value = Rst("EntryTime").Value
End If
End If
rst.Close
The run-time error occurs at the rst open command. When I debug it, the strSQL does not contain any value for where Document.All.Item("txtOrderID").Value should be. Any ideas?