You can use your favorite social network to register or link an existing account:
Or use your email address to register without a social network:
Sign in with these social networks:
Or enter your username and password
Forgot your password?
Yes, please link my existing account with for quick, secure access.
No, I would like to create a new account with my profile information.
Say you need a combo box that is always populated with the last day of the current month, as well as the last days next five months. For example, in May, you want it to look like this:
Then, in June, you want the choices to automatically roll over so that the first date is 6/30/2009, and the last one is 11/30/2009. How do you do this without manually updating the combo box’s data source? Try a callback function. A callback function lets you use VBA code to fill the list with the appropriate values each time the form is opened, so that the list is always current.
Without getting tied up in the details of how a callback function works, here’s a quick-and-dirty procedure showing how to get one working on your Access 2007 form. Afterwards, I’ll give you a few hints on how you can modify the function to suit your needs. (I’ll rely on commenters to point out improvements as well. :-))
Function FillList(ctrl As Control, ID, Row, Col, Action) Select Case Action Case acLBInitialize FillList = True Case acLBOpen FillList = Timer Case acLBGetRowCount FillList = 6 Case acLBGetColumnCount FillList = 1 Case acLBGetColumnWidth FillList = -1 Case acLBGetValue FillList = DateSerial(Year(Date), _ Month(Date) + 1 + Row, 1) - 1 Case acLBGetFormat FillList = "mm/dd/yyyy" Case acLBEnd Case acLBClose End Select End Function
Comments: (1) Collapse
You can also do this quite easily without code, using just the combo/list box's rowsource query, if you have a "seed" table to provide an initial set of numbered records. For example, given a table [Iotas] with field [Iota], containing at least 6 records with Iota = 0 ... 5, then this SQL statement will return month-end dates for this and the next five months: -------
SELECT DateSerial(Year(Date()),Month(Date())+[Iota]+1,0) AS MonthEnd
FROM Iotas
WHERE Iota<6;
------- I find it convenient to have a table of Iotas with 10 records, and can include it in a query multiple times to create as many records as I need for any given purpose. For example, if I needed 5 years (60 months) worth of month-end dates, I could revise the above query like this: -------
SELECT DateSerial(Year(Date()),Month(Date())+[A].[Iota]+(10*[B].[Iota])+1,0) AS MonthEnd
FROM Iotas AS A, Iotas AS B
WHERE ((([A].[Iota]+([B].[Iota]*10))<60));
-------
Comments: (loading) Collapse