Using variables to access a form in Forms Collection

J

JoshPeltier

Hi,
I was wondering if anyone could help me. I have written a functio
which inserts an address into a table, and returns the new address i
to the calling form. Several forms call the function and have generi
control names. here is the code:

Call addAdrs(me.name)

Public Function addAdrs(frmName As Form)
'adds address based on which form contains the information.
'It then returns the new adrs_id.

Dim rsAdrs As DAO.Recordset
Dim sSQL As String

sSQL = "SELECT * FROM tblAddress"
Set rsAdrs = CurrentDb.OpenRecordset(sSQL)

rsAdrs.AddNew
rsAdrs!street = Forms!frmName!txtStreet
rsAdrs!city = Forms!frmName!txtCity
rsAdrs!State = Forms!frmName!txtState
rsAdrs!zip = Forms!frmName!txtZip
rsAdrs!county = Forms!frmName!txtCounty
rsAdrs.Update

rsAdrs.MoveLast
addAdrs = rsAdrs!adrs_id 'returns the new address id

rsAdrs.Close
Set rsAdrs = Nothing
End Function

This is just the last try. I know that it has to do with my functio
argument declaration, and the way I type the form name in the functio
call. If you have any ideas, I would appreciate it.

Thanks,
Jos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top