Thanks to all for the input. I made the changes with regards to the spaces inthe SQL statement and I get another error noW;
Run-Time error '91': Object variable or With block variable not set
Debugger is pointing to this line in the code:
Ws.Cells(1, i + 1).Value = rs.Fields(i).Name
When I change my view of the VBA screen to the "locals window"- these are the values :
Ws = Nothing
Under connection, the value for dbs = <opertion is not supported for this type of object>
I am inclined to believe that my recordset is not being created in the first place.'
I don't know what esle to do. I tried other forums and it seems that no one really has a clear cut working solution for querying access tables using VBA code.
Any additional input will be appreciated. thanks!
__________________________________________________ ___________
Quote:
|
Originally Posted by healdem
mind you it could be somehting kanky n Excel.. as strictly speaking it an Excel / JET problem.. it has nothing what so ever to do with Access.
for the record though I'd agree its almost certainly going to be the SQL that is the problem, (for now)
[/code]Set rs = dbs.OpenRecordset("SELECT * FROM [Pretrial]" & _
" WHERE [Pretrial].[Name] = 'John'" & _
" AND [Pretrial].[Age]= 35" & _
" ORDER BY [Pretrial].[Score];")[/code]
stylewise I'suggest you put a leading space in things such as multiline SQL statements, as its marginally easier to spot in my books
Id also suggest that when you are opening SQL statements, assign the SQL to a variable so that its easy to debug the SQL by repeating it back to the screen in a msgbox, or setting a break point in the code so I can see what the SQL engine is being requested to do, as opposed to what I think the code is doing
eg
[/code]dim strSQL as string
strSQL = "SELECT * FROM [Pretrial]" & _
" WHERE [Pretrial].[Name] = 'John'" & _
" AND [Pretrial].[Age]= 35" & _
" ORDER BY [Pretrial].[Score];"
msbox strsql,vbinformation,"SQL statement is....."
Set rs = dbs.OpenRecordset(strSQL)
[/code]
|