Error while selecting Date in calendar. (1 Viewer)

adaoluz

New member
Local time
Yesterday, 19:28
Joined
May 7, 2018
Messages
2
Hello friends!

I have an error in the line "Runtime Error 2474", "The expression you entered requires the control to be in the active window".

"Line 7 error", thanks for the time to help me.



Code:
Function FormDoubleClick ()
   'When fields are double-clicked, set datSelected
   datSelected = strMonth & "" & Me.ActiveControl.Caption & "," & intYear

   'Close and set value
   DoCmd.Close acForm, "frmMiniCalendar"
   Screen.ActiveControl.Value = datSelected

End Function

Please someone could help me, according to some research the error occasioned, due to regional settings.
I'm new to the forum.

error is caused when I open the 'frmHolidays' form, giving two clicks to the date the mini-calendar form, '' frmminicalendario, '' opens normally. , you can not assign a value to this object, because the access settings, Portuguese_Brazil, since now I thank who can help me.

My office portuguese _brazil.
 

Attachments

  • employees.accdb.zip
    190.9 KB · Views: 38

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:28
Joined
May 21, 2018
Messages
8,527
I would add this function. This will also allow you to use your languages Month names in the month combobox
Code:
Public Function MonthFromString(strMonth As String) As Integer
  Select Case strMonth
    Case "janeiro", "January"
     MonthFromString = 1
    Case "fevereiro", "February"
      MonthFromString = 2
    Case "Marco", "March"
      MonthFromString = 3
    Case "abril", "April"
      MonthFromString = 4
    Case "Maio", "May"
      MonthFromString = 5
    Case "junho", "june"
      MonthFromString = 6
    Case "julho", "July"
      MonthFromString = 7
    Case "agosto", "august"
      MonthFromString = 8
    Case "septembro", "september"
      MonthFromString = 9
    Case "outubro", "october"
      MonthFromString = 10
    Case "Novembro", "November"
      MonthFromString = 11
    Case "Dezembro", "December"
      MonthFromString = 12
  End Select
End Function

Then change this

Code:
Function FormDoubleClick()
    'When fields are double clicked, set datSelected
    datSelected = DateSerial(intYear, MonthFromString(Me.cboMonth), Me.ActiveControl.Caption)
    'Close and set value
    DoCmd.Close acForm, "frmMiniCalendar"
    Screen.ActiveControl.Value = datSelected
   
End Function

I do not get the errors due to my regional settings, so you are likely to still find some other areas that need to be made more regional friendly.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:28
Joined
May 21, 2018
Messages
8,527
There are several other places. Any place they create a date using "strMonth" will not work for you. So look for all those where they try to create a date
datTemp = strMonth & " 1, " & intYear
needs to be changed to this code
datTemp = DateSerial(intYear, MonthFromString(strMonth), 1)

'datFirst = strMonth & ". 1/" & intYear
datfirst = DateSerial(intYear, MonthFromString(strMonth), 1)
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:28
Joined
May 21, 2018
Messages
8,527
https://support.office.com/en-us/article/dateserial-function-a0128476-83a0-407c-831a-93f2b046f503

The date serial is the safe way to create a date because it is not effected by regional settings.
I am surprised that "datTemp = strMonth & " 1, " & intYear" even works. VBA does its best to convert to a date, even though it is not explicitly told to do so. So the problem when you pick
September 19, 2018 it tries to convert it to "09/19/2018" which I assume is not a date since that is the 19th month of the year where in US English it is the 9th month and 19th day.
 

MarkK

bit cruncher
Local time
Yesterday, 19:28
Joined
Mar 17, 2004
Messages
8,181
I think this line of code is inherently unsafe...
Code:
   Screen.ActiveControl.Value = datSelected
You cannot be totally certain what control is going to become current in the Screen object, or that it exposes a .Value property. At the very least, that assignment should be wrapped in some kind of error handling, but better yet, you need to find a way to be completely precise about what control you mean to make that assignment to.
Maybe you need to pass a control reference to the form, or the form needs to establish a reference to that control when it opens, or something like that, to make this process minimally reliable.
hth
Mark
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:28
Joined
May 21, 2018
Messages
8,527
Code:
You cannot be totally certain what control is going to become current in the Screen object, or that it exposes a .Value property
In this case you are nearly 100% certain. That function only fires on those controls that have it in their on double click event. So I know of no way that could fire and the control double clicked on could not be the active control, and since only the textboxes fire this even of course you know they have a value property.
 

MarkK

bit cruncher
Local time
Yesterday, 19:28
Joined
Mar 17, 2004
Messages
8,181
To generate the error the OP is talking about, close all the forms in your database, and do this in the immediate pane...
Code:
? Screen.ActiveControl.Name
I think the problem is ambiguity in identifying that target control. I could be wrong, but that is what it looks like to me.
Mark
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:28
Joined
May 21, 2018
Messages
8,527
Try replacing your calendar form and code with the one used in A Better Date Picker

This may be easier than trying to fix the one you have. In sense all of these home grown calendar controls are about the same. You figure out the start date of the month and offset the controls with the start date. This one should not have the regional settings issues since it uses dateserial to form the dates. In the month combo you can then replace the rowsource:
Code:
1;January;2;February;3;March;4;April;5;May;6;June;7;July;8;August;9;September;10;October;11;November;12;December

With the proper Portugese Names for each month. Since the code uses the first column it will still work.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:28
Joined
May 21, 2018
Messages
8,527
What MarkK is suggesting is not your problem. Please disregard. Your problem has to do with how the developer of the calendar is building dates. The developer's method will only work with US type regional settings. That is why Ridders method should work because it should be agnostic to regional settings. Or you will have to modify the code that you have to be regional agnostic.
 
Last edited:

adaoluz

New member
Local time
Yesterday, 19:28
Joined
May 7, 2018
Messages
2
Good Friends!

Thanks for the tips I was able to solve my problem, until the next !!
:):):)
 

Users who are viewing this thread

Top Bottom