Solved

Calender control dates.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

867 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

12 Experts available now in Live!

Get 1:1 Help Now