Cannot assign a Value

G

Guest

I've placed a command button on a continuous form to open up a form in which
to add a Note to the current project. I'm trying to initialize the record
with the StaffID, ProjectNumber, and Status, but I'm receiving the error
message 2448: "You can't assign a value to this object." I've
double-checked the form and control names--I don't think there are any typos.

Can anyone explain it?

Sprinks

' Command button code
Private Sub cmdNote_Click()
On Error GoTo Err_Handler

Dim stDocName As String
Dim stLinkCriteria As String


stDocName = "ProjectNotes"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd

Err_Exit:
Exit Sub

Err_Handler:
MsgBox "The following error has occurred. Please contact the system
administrator." & _
vbCrLf & vbCrLf & Err.Number & vbCrLf & Err.Description, vbOKOnly,
"Runtime Error"
Resume Err_Exit

End Sub

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Handler

Me![txtStaffID] = Forms![Timesheet]![txtStaffID]
Me![txtStatusID] = 2
Me![cboProjectNumber] =
Forms!Timesheet!TimeSheetDetail.Form![cboProjectNumber]

Err_Exit:
Exit Sub

Err_Handler:
MsgBox "The following error has occurred. Please contact the system
administrator." & _
vbCrLf & vbCrLf & Err.Number & vbCrLf & Err.Description, vbOKOnly,
"Runtime Error"
Resume Err_Exit

End Sub
 
G

Guest

Klatuu,

Thank you; it works. But, in the interest of "learning how to fish", can
you tell me why?

Thanks.

Sprinks

Klatuu said:
Move your code from the Open event to the Load event.

Sprinks said:
I've placed a command button on a continuous form to open up a form in which
to add a Note to the current project. I'm trying to initialize the record
with the StaffID, ProjectNumber, and Status, but I'm receiving the error
message 2448: "You can't assign a value to this object." I've
double-checked the form and control names--I don't think there are any typos.

Can anyone explain it?

Sprinks

' Command button code
Private Sub cmdNote_Click()
On Error GoTo Err_Handler

Dim stDocName As String
Dim stLinkCriteria As String


stDocName = "ProjectNotes"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd

Err_Exit:
Exit Sub

Err_Handler:
MsgBox "The following error has occurred. Please contact the system
administrator." & _
vbCrLf & vbCrLf & Err.Number & vbCrLf & Err.Description, vbOKOnly,
"Runtime Error"
Resume Err_Exit

End Sub

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Handler

Me![txtStaffID] = Forms![Timesheet]![txtStaffID]
Me![txtStatusID] = 2
Me![cboProjectNumber] =
Forms!Timesheet!TimeSheetDetail.Form![cboProjectNumber]

Err_Exit:
Exit Sub

Err_Handler:
MsgBox "The following error has occurred. Please contact the system
administrator." & _
vbCrLf & vbCrLf & Err.Number & vbCrLf & Err.Description, vbOKOnly,
"Runtime Error"
Resume Err_Exit

End Sub
 
D

Douglas J. Steele

The Open event is too early: not all of the controls are instantiated until
the Load event.

Realistically, since the Open event allows cancellation, and the Load event
doesn't, it makes sense to put any code that determines whether or not to
display the form in the Open event, and any code that initializes or formats
the form in its Load event.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Sprinks said:
Klatuu,

Thank you; it works. But, in the interest of "learning how to fish", can
you tell me why?

Thanks.

Sprinks

Klatuu said:
Move your code from the Open event to the Load event.

Sprinks said:
I've placed a command button on a continuous form to open up a form in
which
to add a Note to the current project. I'm trying to initialize the
record
with the StaffID, ProjectNumber, and Status, but I'm receiving the
error
message 2448: "You can't assign a value to this object." I've
double-checked the form and control names--I don't think there are any
typos.

Can anyone explain it?

Sprinks

' Command button code
Private Sub cmdNote_Click()
On Error GoTo Err_Handler

Dim stDocName As String
Dim stLinkCriteria As String


stDocName = "ProjectNotes"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd

Err_Exit:
Exit Sub

Err_Handler:
MsgBox "The following error has occurred. Please contact the
system
administrator." & _
vbCrLf & vbCrLf & Err.Number & vbCrLf & Err.Description,
vbOKOnly,
"Runtime Error"
Resume Err_Exit

End Sub

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Handler

Me![txtStaffID] = Forms![Timesheet]![txtStaffID]
Me![txtStatusID] = 2
Me![cboProjectNumber] =
Forms!Timesheet!TimeSheetDetail.Form![cboProjectNumber]

Err_Exit:
Exit Sub

Err_Handler:
MsgBox "The following error has occurred. Please contact the
system
administrator." & _
vbCrLf & vbCrLf & Err.Number & vbCrLf & Err.Description,
vbOKOnly,
"Runtime Error"
Resume Err_Exit

End Sub
 

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