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

Can't Assign a Value to this Object

Status
Not open for further replies.

ohmbru

Technical User
Jul 13, 2001
161
US
Oh, boy. I am at my wits end! I can't understand why this code isn't working.

I have this bit of code that executes on startup. The variable EUser, Name, and Team are used on the form and I'm trying top set them in the OnCurrent event. I continue to get run-time error 2448, Can't Assign a Value to this Object.

Does anyone know where I'm goinf wrong?

Option Compare Database
Option Explicit

Public EUser As String
Public Name As String
Public Team As String
Public Fld As String
Public ChgInd As String

Public Function StartupStuff()

Dim DForm As String
DoCmd.OpenForm "frmUser", acNormal, , , acFormReadOnly, acHidden
EUser = Forms!frmUser!UserID
Name = DLookup("[tblEmployee]![FullName]", "[tblEmployee]", "[tblEmployee]![UserID]=forms![frmUser]![UserID]")
Team = DLookup("[tblEmployee]![OTeam]", "[tblEmployee]", "[tblEmployee]![UserID]=forms![frmUser]![UserID]")


If DCount("[" & EUser & "]![Date]", EUser, "[" & EUser & "]![Date]") > 0 Then
'Open frmRecover
DoCmd.OpenForm "frmRecover"
Else:
'Open normally
DoCmd.OpenForm "frmBeginSession", acNormal, , , acFormAdd, acWindowNormal
DoCmd.Restore
'****Set RecordSource****
Forms![frmBeginSession].RecordSource = Forms![frmUser]![UserID]
DoCmd.GoToRecord , , acLast
End If
End Function

Private Sub Form_Current()

'Set personal info
Me!FullName = Name
Me!OTeam = Team
Me!User = EUser

Brian
 
Which line produces an error, please provide that, else we just have to guess...

One guess is "Name", "FullName" ans "User". Name is a property of nearly all objects in Access/VBA, FullName ans User are also properties and should be avoided as name of objects/variables you create yourself. Use a naming convention (str to prefix strings, lng for longs...).

Roy-Vidar
 
The error occurs on the first line of the OnCurrent code.

I will rename the variables as you suggest and try it.

Thanks

Brian
 
After renaming these variables I still got the same error.

Brian
 
So you're assigning something like this:

[tt]Me!txtFullname = strName[/tt]

Does strName have any value?

(try using either debug.print, msgbox or other means to to check that all the variables have valid values prior to assigning them to the form controls)

When is the startupstuff run in relation to the on current? From the Form_Load/database open? Are those publics declared within a module or (another) forms module?

- also see there seems to be a "Date" as field name, should also be avoided, cause that's a function.

Sometimes one are not able to assign values, cause the controls in question has a calculated control.

Perhaps repost the new code (at least for me;-)) explain the cronology of the events (startupstuff in relation to current)

- haven't really taken a look at the startupstuff yet, just assumed it's working

Roy-Vidar
 
I rather new to this programming thing, but I had this same bug for about a week. What I found out was, my form was in read only mode and by a flike I went and placed it in edit/write and wa la the bug went away and I can not place a designated variable in a text box.
In my particular form I used a:

DoCmd.GoToRecord acAtiveDataObject, , acLast

Now I may have opened a box that'll bite me, but that is what I did.
Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top