ACC2000: How to Look Up Values Within a Data Access PageID: Q234301
|
This article shows you how to look up values within data access pages by using the existing relationships or by using ActiveX Data Objects (ADO) rather than by using domain functions.
In most Microsoft Access objects, such as forms and reports, you can use a domain function to easily retrieve data from sources other than the record source of the object.
Domain functions are intrinsic functions built into Microsoft Access. Because data access pages are ultimately viewed by using a Web browser (such as Microsoft Internet Explorer), domain functions do not work in data access pages. For example, Internet Explorer does not understand what a DLookup() function is and does not know how to execute the function from within a page.
For this reason, you must use a different approach to look up data within tables that are not bound to the page.
Tables
Orders
Related Tables
Customers
<SCRIPT LANGUAGE=vbscript FOR=MSODSC EVENT=Current(oEventInfo)>The oEventInfo parameter added above is used to return specific information about the event to the script. You must add this parameter, regardless of whether it will be used or not, because the script will fail without it.
<SCRIPT Event=Current(oEventInfo) For=MSODSC Language=VBScript>
<!--
Dim Con
Dim Rst
Set Con = CreateObject("ADODB.Connection")
Set Rst = CreateObject("ADODB.Recordset")
' Use the following statement if you are in Northwind.mdb.
'
' The connection string may vary depending upon the location of the
' database and the system database.
'
Con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program " & _
"Files\Microsoft Office\Office\Samples\Northwind.mdb;Jet OLEDB:System " & _
"Database=C:\Program Files\Microsoft Office\Office\System.mdw;User " & _
"ID=Admin;"
' Use the following statement if you are in NorthwindCS.adp.
'
' You will need to replace "MySQLServer" with the name of your SQL Server
' or MSDE for your data source.
'
' Con.Open "Provider=MSDataShape.1;Data Source=MySQLServer;" & _
' "User ID=sa;Password=;Initial Catalog=NorthwindCS;Data " & _
' "Provider=SQLOLEDB.1"
Rst.Open "SELECT CompanyName FROM Customers WHERE CustomerID = " & _
chr(39) & Document.All.Item("CustomerID").Value & chr(39), Con
Document.All.Item("CoName").Value = Rst("CompanyName").Value
Rst.Close
Con.Close
-->
</SCRIPT>
NOTE: Your database should be in a Web folder or a network folder where all users have access.Additional query words:
Keywords : kbdta AccDAP DAPHowTo DAPScriptHowTo dtavbscript
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 13, 1999