Re: How to reference a Table in a Sub procedure
- From: "George Nicholson" <GeorgeNJunk@xxxxxxxxxxx>
- Date: Thu, 28 Jun 2007 16:57:41 -0500
1)
ctlImagePrefix.Text
Assuming ctlImagePrefix is a Textbox or Combobox, try using
ctlImagePrefix.Value
The Text property is be tricky to use because it requires that the specified
control have the focus. The Value property has no such requirement. This
*may* be why your code wasn't working, but I would have expected a different
error message
2)
If you have a table named Images in the current db then "SELECT * FROM
Images.." is fine.
However, *if* you wanted to do something like this....
"SELECT * FROM " & objTable & "WHERE....."You declared objTable as an object but the select statement wants a text
string (the table name):
Here is one approach to doing the same thing correctly (also note the
additional space before the W):
Dim tdf as DAO.TableDef
Set tdf = CurrentDB.TableDefs("Images")
"SELECT * FROM " & tdf.Name & " WHERE....."
3) For easier debugging, make sure you assign your sql string to a variable:
strSQL = "SELECT * FROM Images WHERE ...."
then, place a breakpoint in your code on the line that will execute your
completed strSQL. When the breakpoint is reached type the following in the
Immediate window (View>Immediate):
?strSQL
What displays will be the string that Access is about to try to execute.
Review space/quote placements, variable/control values, etc., and edit your
code as necessary. Quite often what is wrong is very obvious.
If you are still having problems, show us the entire line that "blows up".
If its something like:
Set rs = CurrentDB.OpenRecordset(strSQL)
Then "Object Required" might not refer to a problem with strSQL, it would
probably refer to the incorrect use of CurrentDB....
HTH,
"rb608" <junkmail608@xxxxxxxxxxx> wrote in message
news:1183065295.951139.152520@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm starting to seriously push my envelope of self-taught
understanding at this point, and I'm stumped at my next step. I've
figured out how passing the variables to the sub procedure works
(whew!); and buoyed by that success, I think as long as I have all of
the same variables I need, why not just put the Recordset operation in
here too.
So, I write up a nice strSelect string ("SELECT * FROM Images WHERE
ImagePrefix = '" & ctlImagePrefix.Text & "....etc. inside the Sub
procedure.
It blows up. "Run time error 424, Object Required."
Aha! I think - I need to put the table "Images" into the variable
list on both ends. so I add ", objTable as Object" to the end of the
Sub variables and add the table name "Images" to the Call variables.
I also rewrite the string to be
"SELECT * FROM " & objTable & "WHERE....."
No good. Now I get "Compile Error: ByRef argument type mismatch."
Clearly I'm over my head here. I've never gotten this deep into the
bowels of Access. I could do trial-and-error for days and never
figure this out. Needless to say, the Help file isn't much help.
What's the correct syntax/procedure for what I'm trying to do?
Tx again.
.
- References:
- How to reference a Table in a Sub procedure
- From: rb608
- How to reference a Table in a Sub procedure
- Prev by Date: Re: Update Query does not clear all records immediately
- Next by Date: Help with lost focus event
- Previous by thread: Re: How to reference a Table in a Sub procedure
- Next by thread: Help with lost focus event
- Index(es):
Relevant Pages
|