Solved

Calender control dates.

Posted on 2004-10-04
2
271 Views
Last Modified: 2012-08-14
Hi,

I have a form with a combo box that is populated with a range of dates from a row in excel.

        With .lsDates
            For i = 1 To rngDates.Cells.Count
            .AddItem Format(rngDates.Cells(i).Value, "dd mmmm")
            i = i + 5
            Next i
            .ListIndex = 0
        End With
    End With

This works fine but I was wondering....
Is it possible to use the inbuilt 'calender control 8.0' in excel VBA to do this, but make it so only the dates in my worksheet are available to choose from. Maybe make the other dates greyed out?

Thanks for any help

Chimplet
0
Comment
Question by:Chimplet
2 Comments
 
LVL 10

Accepted Solution

by:
anv earned 500 total points
ID: 12223820
check the following code

Private Sub Calendar1_Click()
For i = 2 To 30 Step 2
    If Calendar1.Day = i Then
        If Calendar1.Month = 5 Or Calendar1.Month = 7 Or Calendar1.Month = 9 Then
            Calendar1.Day = 7
            Calendar1.Month = 8
        End If
    End If
Next

End Sub


it checks if the day is even and month is 5 , 7 or 9 then set the date of day 7 and month 8..

here u can replace the loop with ur loop...comparing te current date with the database values..

like

while not rs1.eof
 
  for i = 0 to lstdates.listcount -1
   if datepart("d",format(rs1!DateVal,"DD/MM/YYYY")) = lstdates.list(i) then
       'do something  since date found in the list controls
   else
    'continue with the loop
   end if
  next
  rs1.movenext
wend
0
 

Author Comment

by:Chimplet
ID: 12251664
Thanks  anv

I will work on your answer later this week.

Chimplet

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question