Solved

Calender control dates.

Posted on 2004-10-04
2
268 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now