Help with code to insert a variable into a table record

J

June

Thanks for taking the time to respond

I have code which is called from the switchboard that gets the current user logged into my database and then adds that user to the table field. Problem is I can't get it to work. Not sure if I have something in the wrong place or the wrong code or both. I am using Access 2002. Please give me an example because I don't know what I am doing here. This is my code in a module

Function WhoUsesDb(
Dim rs As DAO.Recordse
Call GetUserName ' Gets the user name -works okay
Set rs = CurrentDb.OpenRecordset("tblUsers") 'table name is tblUsers, Field name is Use
With r
rs.Edi
rs.AddNe
rs![User] = ap_GetUserNam
rs.Updat
End Wit
rs.Clos
Set rs = Nothin
 
A

Al Borges

Hi June:

First of all, what does "I can't get it to work" mean? Did you get an error
message, or did it run but failed to return a new record? That said, check
to make sure that your references (open module>> in menubar select Tools>>
References) include
- Microsoft Visual Basic for Extensibility 5.3
- Microsoft DAO 3.6 Object Library

Regards,
Al

June said:
Thanks for taking the time to respond.

I have code which is called from the switchboard that gets the current
user logged into my database and then adds that user to the table field.
Problem is I can't get it to work. Not sure if I have something in the
wrong place or the wrong code or both. I am using Access 2002. Please give
me an example because I don't know what I am doing here. This is my code in
a module:
Function WhoUsesDb()
Dim rs As DAO.Recordset
Call GetUserName ' Gets the user name -works okay.
Set rs = CurrentDb.OpenRecordset("tblUsers") 'table name is tblUsers, Field name is User
With rs
rs.Edit
rs.AddNew
rs![User] = ap_GetUserName
rs.Update
End With
rs.Close
Set rs = Nothing
 
J

June

I don't get an error but the table doesn't get updated. I do have the two references loaded.
 
J

June

Maybe the problem is that I have the wrong code to create a new record in my table with the user's name. What do you think?
 
A

Al Borges

I hate it when people post garbage and then disappear...

Al

Al Borges said:
Hi June:

First of all, what does "I can't get it to work" mean? Did you get an error
message, or did it run but failed to return a new record? That said, check
to make sure that your references (open module>> in menubar select Tools>>
References) include
- Microsoft Visual Basic for Extensibility 5.3
- Microsoft DAO 3.6 Object Library

Regards,
Al

June said:
Thanks for taking the time to respond.

I have code which is called from the switchboard that gets the current
user logged into my database and then adds that user to the table field.
Problem is I can't get it to work. Not sure if I have something in the
wrong place or the wrong code or both. I am using Access 2002. Please give
me an example because I don't know what I am doing here. This is my code in
a module:
Function WhoUsesDb()
Dim rs As DAO.Recordset
Call GetUserName ' Gets the user name -works okay.
Set rs = CurrentDb.OpenRecordset("tblUsers") 'table name is tblUsers, Field name is User
With rs
rs.Edit
rs.AddNew
rs![User] = ap_GetUserName
rs.Update
End With
rs.Close
Set rs = Nothing
 

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