Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

useing VBScript function with ADODB connection problem...

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
US
Hello,

Question: How can I use ADO within a VB Script function?

Problem:
I'm useing a drop down menu to select the type of info to search for in a dbf file. Upon selection of the info type, it calls a vbscript that will execute the proper function based on the users selection. Within the vbscript, I want it to connect useing ADO to dbf file (using ODBC DSN connection) for further selections. However my problem is that an error keeps comming up with the ADO script.

If I use: Set conn = Server.CreateObject("ADODB.Connection")
Then I get the error: Error: Object required: 'Server'

or if I use: Set conn = New ADODB.Connection
I get the error: Error: Class not defined: 'ADODB'

Here is the entire vbscript I use:


<head>
<script language=&quot;vbscript&quot;>
<!--
Sub getMore(types)

Dim sql
sql = &quot;SELECT Item.Product, Item.Manufact, Item.Type FROM Item WHERE ((Item.Type)='&quot; & types & &quot;');&quot;

Set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
DSNtemp = &quot;item&quot;
conn.Open DSNtemp
Set rs = conn.Execute(sql, 3, 3)

response.write(&quot;msgbox(&quot;&quot;&quot; & rs(&quot;Product&quot;) & &quot;&quot;&quot;), vbokonly, &quot;&quot;Products&quot;&quot;&quot;)

Set rs = nothing
conn.Close
Set conn = nothing

End Sub
-->
</script>

</head>
<body>

<FORM name='selection' method='post' action='done.asp'>
<SELECT NAME='type' id='selectType' onChange='getMore(document.selection.type.value)'>
<OPTION value=''></OPTION>
<OPTION value='Software'>Software</OPTION>
<OPTION value='Network Card'>Network Card</OPTION>
<OPTION value='Printer'>Printer</OPTION>
<OPTION value='Laptop'>Laptop</OPTION>
</SELECT>

<BR>

<DD><Input type='submit' value='Submit'><Input type='Reset' Value='Reset'>
</FORM>


</body>




Can anyone tell me how to do this properly?

Thanks in advance!
-Ovatvvon
 
The first major thing you need to realize is that the vbscript you are running (as event code for the onchange event) is running client-side - NOT on the server.

Therefore, you cannot do SERVER.createobject and you can't do Response.write or any other server-side stuff.

Try changing it to just &quot;CreateObject&quot;, write an ActiveX control, or look into using Remote Data Services (RDS) using the DataSpace and DataFactory objects. Which option to use depends a lot on your client's machines - such as do they have MDAC installed; do they have the ODBC driver you need to use installed; can you connect without a DSN; will they all change (reduce) their security settings to allow this stuff to run/install.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top