creating multiple pop up calendars in a form???

D

dplove

I have written the code to have a calendar pop up when clicking on a combo
box called Date Shipped. It worked fine. I then realized that I had two
more date fields that I would like for this calendar to pop up when clicked.
One is called "Lease term Begin Date" & "Lease term End Date". When I build
the code for the Lease term Begin date I get the following error message

"The expression On Mouse Down you entered as the event property setting
produced the following error:Member already exits in an object module from
which this object module derives."

Here is what my code says:

Option Compare Database
Dim Lease_term_Begin_Date As ComboBox





Private Sub Date_Shipped_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub Date_Shipped_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Set Lease_term_Begin_Date = Date_Shipped
ocxCalendar.Visible = True
ocxCalendar.SetFocus
If Not IsNull(Date_Shipped) Then
ocxCalendar.Value = Date_Shipped.Value
Else
ocxCalendar.Value = Date
End If
End Sub

Private Sub Lease_term_Begin_Date_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub Lease_term_Begin_Date_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
ocxCalendar.Visible = True
ocxCalendar.SetFocus
If Not IsNull(Lease_term_Begin_Date) Then
ocxCalendar.Value = Lease_term_Begin_Date.Value
Else
ocxCalendar.Value = Date
End If
End Sub

Private Sub ocxCalendar_Click()
Lease_term_Begin_Date.Value = ocxCalendar.Value
Lease_term_Begin_Date.SetFocus
ocxCalendar.Visible = False
Set Lease_term_Begin_Date = Nothing
End Sub

Private Sub ocxCalendar_Updated(Code As Integer)

End Sub

This line "Set Lease_term_Begin_Date = Date_Shipped " I also put in the
"Private Sub Lease_term_Begin_Date_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)" and it didnt' work.

All the text boxes where changed to combo boxes. I have not had a change
to try the calendar on the third date field because I can't get the second
one to work. With the code above it doesn't allow my first date field to
work. If I remove everything for the second date field it will work again.

Please tell me what is wrong in this code!!!!

Thanks
 
K

Klatuu

I don't see any reason to use combo boxes for this. What will you do with
the drop down part? Text boxes would be a better choice. Also, I would
suggest you create one function to get the value from the calendar popup and
use it in the Double Click event of each text box where you want a date.
Then the user can either enter the date manually or double click in the text
box to get the calendar.

Private Sub GetCalendarDate()
Dim ctl As Control

Set ctl = Screen.ActiveControl

With ocxCalendar
If IsNull(ctl)
.Value = Date
Else
.Value = (ctl)
End If
.Visible = True
.SetFocus
ctl = .Value
ctl.SetFocus
.Visible = False
End With
Set ctl = Nothing
End Sub

Disclaimer - Untested air code, but it should be close
And to use it:

Private Sub Lease_term_Begin_Date_DoubleClick()
Call GetCalendarDate()
End Sub
 
D

dplove

I created combox boxes because I was following some instructions that I found
on this website (it was a link to a page).

If you suggest this I will do this but will it work for all three text boxes
(thats what I am going to change the combo boxes too). Because I am new to
this, can I take this code and put it in place of the old code? The way I
did it was clicking on the properties of the box and going to "event" and
clicking on mouse down, if not how do I put this code in?

Thanks
 
K

Klatuu

Yes, but not the mouse down event.
I modeled the way I did so the user can either enter the date or select the
calendar by double click. If you want the user to always use the calendar,
then use the Got Focus event.
 
D

dplove

Thanks, I will try this tomorrow.

Klatuu said:
Yes, but not the mouse down event.
I modeled the way I did so the user can either enter the date or select the
calendar by double click. If you want the user to always use the calendar,
then use the Got Focus event.
 
G

Geoff Hoffman

I'm trying to do the same thing and also followed the combo box procedure listed elsewhere (http://www.fontstuff.com/access/acctut09.htm). I am trying to follow the text box method listed above. I am unclear as to where to enter the code. It seems as if there was a double click code and then the larger code above. Where do each of these get inserted? Does one put the larger code in on the OnClick property for each text box? Where does the smaller code go? Thanks so much and sorry if I'm being obtuse.

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
J

John W. Vinson

I'm trying to do the same thing and also followed the combo box procedure listed elsewhere (http://www.fontstuff.com/access/acctut09.htm). I am trying to follow the text box method listed above. I am unclear as to where to enter the code. It seems as if there was a double click code and then the larger code above. Where do each of these get inserted? Does one put the larger code in on the OnClick property for each text box? Where does the smaller code go? Thanks so much and sorry if I'm being obtuse.

"above" includes about ten years' worth of posts by tens of thousands of
people. Sorry, I'm disinclined to do a Google search to find what you're
referring to.

Please include the code that you're trying to implement in your message, with
an explanation of what you want it to accomplish. You're not the only person
asking questions here after all!

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top