View Full Version : Runtime error 2448: you can't assign a value to this object.access
I created a calendar and the user clicks on a particular date of which the date should auto-populate a blank text field...However, I receieved the follwoing message: runtime error 2448: you can't assign a value to this object. access. How can I resolve this error?
Thanks for your contributions!:friends:
Here is the code for the pop-up calendar:
Function PopupCalendar(ctl As Control) As Variant
'
' This is the public entry point.
' If the passed in date is Null (as it will be if someone just
' opens the Calendar form raw), start on the current day.
' Otherwise, start with the date that is passed in.
'
Dim frmCal As Form
Dim varStartingScheduleDate As Variant
'ctl = ""
varStartingScheduleDate = IIf(IsNull(ctl.Value), Date, ctl.Value)
DoCmd.Openform CALENDAR_FORM, , , , , A_DIALOG, varStartingScheduleDate
' You won't get here until the form is closed or hidden.
'
' If the form is still loaded, then get the final chosen date
' from the form. If it isn't, return Null.
'
If isFormLoaded(CALENDAR_FORM) Then
Set frmCal = Forms(CALENDAR_FORM)
ctl.Value = Format(DateSerial(frmCal!Year, frmCal!Month, frmCal!Day), "dd-mmm-yyyy") - THIS LINE IN MY CODE IS HIGHLIGHTED IN YELLOW
DoCmd.Close A_FORM, CALENDAR_FORM
Set frmCal = Nothing
End If
End Function
Aflatoon
12-20-2011, 05:50 AM
How did you call that code? Specifically, what control did you pass it?
The control you are asking me about...would that be the control source of in the properties I created my object? Thanks, sorry I'm a little less experienced troubleshooting vba errors.:doh:
Aflatoon
12-21-2011, 06:56 AM
No - when you call that function in your code, you have to pass it a control to return the value to. What is that control?
Hi Aflatoon,
Here is the control that returns a value in my code:
Private Sub cmdSearch_Click()
On Error Resume Next
Dim sSql As String
Dim sCriteria As String
sCriteria = "WHERE 1=1 "
Aflatoon
12-22-2011, 04:00 AM
No - that does not call PopupCalendar.
Hi Aflatoon, here it is:
Option Compare Database 'Use database order for string comparisons
Option Explicit
Const CALENDAR_FORM = "frmCalendar"
Type udDateType
wYear As Integer
wMonth As Integer
wDay As Integer
End Type
Private Function isFormLoaded(strFormName As String)
isFormLoaded = SysCmd(SYSCMD_GETOBJECTSTATE, A_FORM, strFormName)
End Function
Aflatoon
12-22-2011, 04:15 AM
Where do you think that calls the PopupCalendar function?
Somewhere in your code you must have a call to PopupCalendar that also passes a control to that function. That is what I am asking to see.
Hi Aflatoon, here is an onpush property I noticed in my code.
Private Sub ChangeDate(strMoveUnit As String, intDirection As Integer)
' Called from OnPush property of the next/previous month/year buttons.
Dim intMonth As Integer
Dim intYear As Integer
Dim intDay As Integer
Dim varDate As Variant
Dim varOldDate As Variant
Dim intInc As Integer
Dim rstrInterval As String
On Error GoTo ChangeDateError
' Get the current values from the form.
intYear = Me!Year
intMonth = Me!Month
intDay = Me!Day
intInc = IIf(intDirection = MOVE_FORWARD, 1, -1)
varOldDate = DateSerial(intYear, intMonth, intDay)
varDate = DateAdd(strMoveUnit, intInc, varOldDate)
If (intDirection = MOVE_BACKWARD And varDate > varOldDate) Then
' This should only happen when you go backward from
' 1/1/100 to 12/31/1999. Just a quirk of Access' date
' handling!
Exit Sub
End If
intMonth = DatePart("m", varDate)
intYear = DatePart("yyyy", varDate)
Me!Day = DatePart("d", varDate)
' If the month and year haven't changed, then just
' move to the selected day. It's a lot faster.
If Me!Month = intMonth And Me!Year = intYear Then
HandleIndent "lbl" & Day2Button((Me!Day), intStartDOW)
Else
' Set the values on the form and then display the new calendar.
Me!Month = intMonth
Me!txtMonth = GetMonthName(intMonth)
Me!Year = intYear
DisplayCal
End If
ChangeDateExit:
Exit Sub
ChangeDateError:
Resume ChangeDateExit
End Sub
Aflatoon
12-22-2011, 04:57 AM
One last time: do you see the word 'PopupCalendar' anywhere in that code?
Perhaps it would be simpler if you told us where you got the code from in the first place?
Hi Aflatoon, here is where I found the sample pop up calendar/scheduling system I would like to incorporate into a database I am developing...its the version of the pop calendar zip...
http://www.access-programmers.co.uk/forums/showthread.php?t=103387
Thanks!
Aflatoon
12-22-2011, 05:41 AM
I see - so assuming you have used the same layout, what do you have in the On Dbl Click event of whichever control you are populating with the calendar?
Hi Aflatoon, here is
Option Compare Database
Option Explicit
Sub subOpenAddingDataForm()
DoCmd.Openform "frmAddingData", , , "CustomerID =" & CustomerID
Form_frmAddingData.cmdAddNewData.Visible = False
Form_frmAddingData.AllowEdits = False
Form_frmAddingData.AllowAdditions = False
Form_frmAddingData.AllowFilters = False
Form_frmAddingData.AllowDeletions = False
End Sub
Private Sub FirstName_Dbl(Cancel As Integer)
Call subOpenAddingDataForm
End Sub
Private Sub StartingScheduleDate_Dbl(Cancel As Integer)
Call subOpenAddingDataForm
End Sub
Private Sub Venue_Dbl(Cancel As Integer)
Call subOpenAddingDataForm
End Sub
Private Sub Location_Dbl(Cancel As Integer)
Call subOpenAddingDataForm
End Sub
Private Sub Surname_Dbl(Cancel As Integer)
Call subOpenAddingDataForm
End Sub
Private Sub Title_Dbl(Cancel As Integer)
Call subOpenAddingDataForm
End Sub
The calendar appears on a subform and when the user clicks on a date...it populates a textbox called date...
Does that answer your question?
Thanks!
Aflatoon
12-22-2011, 06:18 AM
At this point, I am going to have to say that unless you can post your database (no data necessary), I cannot assist you, I'm afraid.
Ok...I'll send it to you.
Hi experts,
I've enclosed the database...bizarrely my buttons to add a subform, to clear the data, to close the was working fine and now they aren't would you know what is triggering this issue? The only issues I had before was the search button display the results from the table and also the print preview button...as you open the database the on load event seems to have an issue with one of my fields. Anyway you have the link of the original...maybe you can compare where my database is having the issues compared to the original version.
Thanks!
Aflatoon
12-22-2011, 08:27 AM
Are you using Access 2003? (or is that just the db format)
Aflatoon
12-22-2011, 08:41 AM
The data source for the subform on your startup form is looking for a control on the main form that does not exist (Venue) which is why you get the error.
Furthermore, almost all of the code in that form has errors because it refers to controls and/or fields that do not exist. In point of fact, when you comment out all the code that will not compile, the Calendar part does actually work.
Hi Aflatoon, I was wondering based on the template and functionality of the sample search 2003 database...could I possibly change the field names to adapt to utilise with what I would like to do? Can this be done? If so, what steps would I need to consider when changing the field names? What springs to mind is creating it in a new database, but I would like to keep the same format...in other words could I change the field and control names if I recreated it in a new database but kept the same template and functionality?
I will be using access 2010 to re-develop this database. Is this possible to do?
Thanks
Aflatoon
12-28-2011, 10:54 AM
It would, in my opinion, be easier to start from scratch and then add any functionality from the sample database to your database once you understand how it works. It is difficult to be much more specific than that, I fear.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.