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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass a table name to a function to open a recordset

Status
Not open for further replies.

sub5

Programmer
Oct 12, 2005
104
Hi

When I try to pass this table name from procedure1 to function1 it tells me "object variable or with block variable not set"

private sub procedure1
call function1("T-Table1")
end sub

private function function1(strTable as String)
dim db as database, rst as recordset
set rst = db.openrecordset(strTable)
rst.edit
rst!field = 300
rst.update
end function

Is it possible to pass a table name?
 
try diming rst as object, and db.openrecordset to currentdb.openrecordset.

ChaZ

There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.
 
a couple of things to try
[blue]dim db as dao.database, rst as dao.recordset[/blue]
make sure you have a reference to DAO
and you forgot
[blue]dim db = currentdb[/blue]
and possibly try
[blue]rst.field("fieldname").value = 300[/blue]

it should work ask long as the string you pass is a valid table or select query name

[η][β][π]
 
it works when i add the line in the function
set db = currentdb
cheers blorf
 
Glad to help.

There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top