Form - Cannot Assign Value

This is weird. I have another db set up to do a similar thing, but cannot replicate it here.
I have a form that has a bunch of buttons on it to run reports. I want to capture when the form was opened, and who opened it. I put two non-visible controls on the form "OpenDate" and "User". I created a table with these two fields. The idea is to log the current date/time, and the userID in those fields when the form is opened. On the Form_Open event, I have:

Me.OpenDate = Now()
Me.User = GetUserCredentials(2)

I get a 'You can't assign a value to this object' error for the first line, and 'Sub or Function not defined' for the second line.

Who is Participating?
NEVAEHSINConnect With a Mentor Commented:
Do you have a module in the first data base with the code for the function "GetUserCredentials(2)"?
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
Forget the hidden controls on the form ... no need.  Instead, do this:

Private Sub Form_Load()
Me![OpenDate] = Now()
Me![User} = GetUserCredentials(2)
End Sub

This writes directly to your fields in the table.

I think because you are using form_open instead of form_load, and the controls are bound you are getting the error.  Try moving your code to the form_load instead.
4charityAuthor Commented:
I added the module for the function "GetuserCredentials(2)", and I removed the hidden controls on the form.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.