Problem with passing values from Calendar Control 10.0

MobiusDick

Hippy Materialist
Local time
Today, 07:51
Joined
Aug 23, 2007
Messages
23
Hi All,

I'm in the process of creating a database that allows users to enter details into a form which includes a date range as start and end dates.

I have used the inbuilt Calendar Control 10.0 control to allow users to select the date. It is linked to two combo boxes [cmbStartDate] and [cmbEndDate] using the following code (this code is repeated for each combo box):

Code:

Private Sub cmbStartDate_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Set cmbOriginator = cmbStartDate

ocxCalendar.Visible = True

ocxCalendar.SetFocus

If Not IsNull(cmbStartDate) Then

ocxCalendar.Value = cmbStartDate.Value

Else

ocxCalendar.Value = Date

End If
End Sub



And..

Private Sub ocxCalendar_Click()

''Update the ComboBox with the value entered into the ComboBox
''Put the value back into the relevant ComboBox
cmbOriginator.Value = ocxCalendar.Value

''Hide the calendar
cmbOriginator.SetFocus
ocxCalendar.Visible = False

''Clear the variable
Set cmbOriginator = Nothing

End Sub

This all seems to work fine- however, when I try to write the selected dates to a table or use them in a query they are not recognised (the form obviously needs to be open whilst the query runs), but if I manually type dates into these combo boxes these dates are picked up fine.

This is beginning to drive me mad so any help would be greatly appreciated.

Mark
 
Why are you using a ComboBox rather than just a TextBox? Why not use the GotFocus or OnEnter event rather than the MouseDown event? Why do you need the following line? Set cmbOriginator = cmbStartDate
 
Hi RuralGuy,

Thanks for the response:

The reason for the line:
Set cmbOriginator = cmbStartDate

is that I am using the same calendar to choose dates for both cmbStartDate and cmbEndDate. Therefore, cmbOriginator is a variable.

Also the reason I choose combo boxes rather than text boxes was to prompt users to anticipate a choice rather than just enetr a date more than anything- although if you think this is the problem i will change it and try again- however, it is possible to reference a combo box in a query (as I have done in another part of the same form), so would this really make a difference?
 
Actually I don't think it is the source of your problem, I was just curious. The Set key word instantiates an object and I didn't think the Calendar needed that.
 
Hello All,

I've just re-read my post and I've missed out a vital piece of information: When the user has selected the relevant dates from the calendar control I am attempting to write the information to a table using an append query with [FORMS]![frmUpdate]![FieldName] syntax.

This works for all manually typed information from other fields on the form-but not for the VB-inserted dates from the control.

Does anyone know why?

Thank you

Man...is a tame or civilized animal; never the less, he requires proper instruction and a fortunate nature, and then of all animals he becomes the most divine and most civilized; but if he be insufficiently or ill- educated he is the most savage of earthly creatures. (Plato)
 
Takes a *lot* of extra code doesn't it? Where do you have your "save" code? Is it behind a command button? What is the exact code you are using to save the ComboBox values? A ComboBox is a different animal and prefers to have a RowSource and a bound column. Try using a TextBox as a test and I'll bet you get better results. I'm always curious why anyone feels the need to use an unbound form. Care to share your reason?
 

Users who are viewing this thread

Back
Top Bottom