Forum Moderators: open
IE:
"SELECT * FROM Contents WHERE Name = " & VARIABLE
Is it possible to do that? I've made numerous attempts at this and always ended up killing my brain thinking it's impossible yet in theory it should work.
I've used the code
"SELECT * FROM Contents WHERE Name = '" & Variable & "'" but it says "Item cannot be found in the collection corresponding to the requested name or ordinal." and when I don't have the ' 's it says "[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1." Any ideas anyone?
Thanks,
IE:
I want to find a column in the Table Content1 where the column Name is the same as the value of variable "strMyVar".
In my code, I use DSNLess connection, so basically, I am using primitive method of declaring a SQL String, and submit the SQL query alongside with the record set query.
Here's a snipplet of my code:
Set con = Server.CreateObject("ADODB.Connection")
con.Open "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & Server.MapPath("database.mdb") & ";"
Set rs = Server.CreateObject("ADODB.Recordset")
SqlStr = "SELECT * FROM Contents1 WHERE Name = '" & SubDiv & "'"
rs.Open SqlStr,con
When I use the above code, it tells me that:
"Item cannot be found in the collection corresponding to the requested name or ordinal." Even though I have made sure to triple check that the database.mdb contains a table called Contents1 and there is a column called Name, and the default value of SubDiv (Main) is included in the column. I've also made sure that it was in the same case incase if it is cAsE SenStive. I don't know what else there is to do... so here I am... lol :) Thanks all.
If you were using a real database other than Access it would be far easier as the structure is often held as a table.
In access w/ ADO you could probably do something like;
SELECT TOP 0 *
FROM SomeTable
Assuming we open this query in objRecordset then we could do something like this - assuming sTheFieldName holds the name of the field you want to look for and that bFieldExists stores the result;
bFieldExists = False
For Each objField In objRecordset.Fields
--If StrComp( objField.Name, sTheFieldName, vbTextCompare ) = 0 Then
----bFieldExists = True
----Exit For
--End If
Next
- Tony