Vary default value for a combobox

degimp

New member
Local time
Today, 10:17
Joined
Aug 20, 2010
Messages
7
I'm new at this, so I hope I describe what I'm looking for effectively. I'm very poor at writing code, but do well with access. I'm using access 2007 and what I'm trying to do is make the default for a combobox change due to what time it is. I have a table with each hour in it and I'm using it in my combobox. What I want to do is have the default change for the current hour that it is. I have been searching for 3 days now and can't find what I'm looking for, probably just not wording my question properly.
 
you could acheive this in 2 ways, depending on how precise you need to be.

#1 would be to include a little code in the forms onCurrent event to set the default according to the time. This could mean the default technically being wrong if the Current event triggers at say 05:59 but the record remains unchanged until 06:00 say

#2 would be to include the code to update the default value in the forms OnTimer event. Depending on the time interval you set this should nearly always be up to date.
 
I'd avoid the Timer suggestion as it uses much more overhead on the computer. I would go with the On Current event.
 
Here is my row source code from when I select SQL view.
SELECT Hourtbl.[Hour#]
FROM Hourtbl;

The on current event should work, because I would like for it to update when the Hour combobox is selected. I have played with the default and on got focus properties and I can't get it figured out. If you have any code suggestions for me that would be great.
I have created a default hour query, but don't have any luck incorporating it into what I am wanting.

SELECT Hourtbl.[Hour#], TimeValue(Now()) AS Expr1
FROM Hourtbl
WHERE (((TimeValue(Now())) Between [Start] And [End]));

Here is one line from my Hourtbl
Hour# Start End
2:00 AM 2:00:00 AM 2:59:59 AM
 
You wouldn't need to change the row source at all. All you would need to do in the Form's On Current event is to set the default:

Code:
Me.ComboNameHere.DefaultValue = Format(Time, "h:00 AM/PM")
 

Users who are viewing this thread

Back
Top Bottom