A better way.

Gannet

Registered User.
Local time
Yesterday, 19:14
Joined
Sep 21, 2006
Messages
55
I have a form (frmCalendarSelection) with all months of a year displayed. Upon changing the year I have code that will cycle through all the subforms and redraw the months to correspond to that year. The problem I ran into though was hiding those days that were either before the first of the month or after the last day. The only way I was able to stop from getting the error that indicated you can't hide a control that has the focus was to put a control called focus_ctl on the subforms that it would set focus to before trying to hide the control. Is there a better way to take focus off a control other than specifying another control?
I've included the work in progress.

Thanks in advance
 

Attachments

I don't know of any way to hide a control except to set the focus elsewhere. But after looking at your year calendar, I put together two forms and one table that might make this whole project much easier to maintain. I have put them into your database and have attached that to this message. One of the two forms is a sample of how to use one form for all 12 months. I would then suggest you go here to see how Allen Browne does a one month calendar. It is great!

I have left the 12 "control type" of text boxes visible only for making it easier to see what is happening in the 12 month form. The 12 "control type" of text boxes are name "Jan", "Feb", "Mar", etc and the Control Source for each field is set to it's month number, "=1", "=2", "=3", etc. Then in the subform control that always uses the same form, "frmMyMonthNumer", the subform control references the month for this subform position on the year calendar. So, the subform control for Jan will reference the MasterField of "Jan". Because the form "frmMyMonthNumer" uses the table "tblMonthNames", the correct month is selected for the correct subform control and gives the form within that subform control the month number and name it will need to format itself for the month position it is in. Boy that sounds confusing to me to. I hope you can follow at least the sample, if you are the least bit interested.
 

Attachments

Smaller but not faster

Ok I've taken your advice GolferGuy and used a single form in place of multiple forms for my months. This has drastically reduced the amount of forms and code needed but I'm still looking for a better way to create (redraw) the months when I switch between years. It currently only takes a few seconds but I feel that there may be a more efficient way to do this. I'm looking to incorporate this piece into a larger database so any way of making this more compact and efficient helps. If no one knows of a way then I can live with it.:rolleyes:

I've included the changes in the database attached.
 

Attachments

Maybe golfer (Vic) can confirm a yes or no on this, but it might be possible to speed up the refresh if you make a variable that is public in the month form and you can use that as your point of reference, instead of each control calling the previous control and iterating through (like day2 = day1 + 1, day3 = day2 + 1). Doing this may speed things up a bit, but without going through it myself and trying it out, I can see a potential problem being that you have multiple copies of the same form open as sub-forms, so this may or may not cause a problem.

BTW, your main form is designed very nice, especially for having 12 copies of the same sub-form open. I'm curious to know if you are going to design a "list view" of just those items entered into your calendar system (kind of like what Outlook does with Appointments). Also, I wonder if using some sort of Calendar control would be of any help - though I don't know off the top of my head, if there are any that will let you designate whether there is an event/item listed on a certain date by allowing you to control the text of those dates (ie. bolding them). Most date controls that I know of, are used for "date pickers" but not sure if they can or can't be used for event/calendar management.
 
Last edited:
Gannet,
I went through your calendar form and put in the little calendar form I had sent for you to look at. I did some non-minor modifications to that sample calendar form so it would work. I was quite sure it would speed up the opening of the calendar selection form with all 12 months on it, and it sure does speed it up. Changing years is lightening fast too. Allen Browne has a very tight algorithm for placing the dates on the form. Of course this calendar does not have the code to highlight dates with a task or note associated with that date, but I just wanted to share with you that this Allen Browne calendar is a solid, and quick, model to start with.
 

Attachments

Ok, I think we're making real progress.

The changes you gave me GolferGuy were just what I was looking for. Unfortunately I have run into a new snag in the program. In the original I used the code
Code:
Screen.ActiveControl
when clicking on a day to pull the date saved within that textbox. This was used as an argument passed onto my frmCalendarEvents form to filter only events on that day. Now that they're labels I don't know how to get values from the label clicked. I'm sure I could create a date if I was able to grab the caption from the label I clicked. Any ideas?
 

Attachments

Won't work for this situation.

That would work if I specified code for each label in it's click event but even then I don't think it would work here. I have a function called clickDate() that takes the value of the currently selected control. The problem is it's taking the value of the month name (text726) since clicking a label doesn't make it active.
 
Looks like you have 42 labels to change into 42 text boxes. If you did not know this, you can right click on a label, then select "Change To", then choose Text Box. I have not found any way to do multiple labels at once.
 
You could modify your clickDate() procedure to take in the date of the clicked control, and pass the caption value to the clickDate procedure my making it say

=clickDate(me.labelname.caption)

Unfortunately, you will have to put the unique label name into each label, but if switching from your original textbox to labels was quicker, I wouldn't switch back to textboxes again.
 
The new calendar form that I supplied as a sample uses labels rather than text boxes, so the switch was from the original calendar to the form I supplied as a sample. The choice was to use the sample form rather than make changes to the original calendar form to incorporate the ideas shown in the sample.
 
Ok changed them back

I guess I was to focused on using the other form that I never thought that it would work if I modified too much. Anyway, I've got it all working and not only is it much quicker than my original but much smaller. Thanks everyone... esp GolferGuy.
 
You're welcome. I always think it fun when it starts working the way we want. I'm glad I could help.
 
I would highly recommend you start a new thread. This is a separate problem.
 
I agree with GolferGuy, though I was a bit curious about this myself. I did download the attached file and check it out - thought it might have something to do with your captions/text fields being unbound, but if that were the case, then it shouldn't preview properly either (theoretically).

I was curious about what answer came about, so I didn't say anything further until/unless someoone else posted the answer.

Anyways, in additon to re-posting, I would probably use the Forms section, rather than Modules/VBA.
 

Users who are viewing this thread

Back
Top Bottom