Crimius
Crimius

Reputation: 534

VBA Set Recordet using a variable table name

I'm trying to access a form's recordset clone from a called function which we're using to essentially dump the data in the recordset into a table we're creating. I'm trying to call the form from the Forms collection, but I can't figure out how to insert the form name (held in a string passed to the function) into the middle of the set statement. Here's what it looks like basically:

Public Function EditFormData(frmName As String)
  Dim strSQL As String
  Dim strTableName As String
  Dim rst As DAO.Recordset
  Dim i As Integer

  Set rst = Forms![[[frmName]]].RecordsetClone

I'm at a bit of a loss here. For this particular function, I could pass a recordset to the function, but I have similar quandaries in another place, where passing one isn't an option. Thoughts?

Upvotes: 2

Views: 1073

Answers (1)

mwolfe02
mwolfe02

Reputation: 24207

Try this:

Set rst = Forms(frmName).RecordsetClone

Upvotes: 3

Related Questions