+- 30 Days

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I get a combo box to have a series of dates in it. I want the
currentdate to be the default, but I need -30 days and + 30 days from the
current date to show.

Any ideas?
 
How do I get a combo box to have a series of dates in it. I want the
currentdate to be the default, but I need -30 days and + 30 days from the
current date to show.

Any ideas?

Add a combo box to your form.
Set it's RowSource Type property to Value List.
Code the Form's Load event:

Dim intX As Integer
Dim strRowSource As String
For intX = -30 To 30
strRowSource = strRowSource & Date + intX & ","
Next intX
strRowSource = Left(strRowSource, Len(strRowSource) - 1)
ComboName.RowSource = strRowSource
 
Fred, I get a compile error when I try to view the form.

I added a combo, cboDate, to the form and set the value list. The bound
column is 1 and it is controlled by a field in tblOvertime.Date

The last line of your OnLoad code that I changed is
cboDate.Date = strRowsource

I get that compile error when I go from form desing to form view.

Ripper
 
See my comments in-line below:

Fred, I get a compile error when I try to view the form.

I added a combo, cboDate, to the form and set the value list. The bound
column is 1 and it is controlled by a field in tblOvertime.Date

For one thing, Date is a reserved keyword in Access/VBA and refers to
the Date function. It should not be used as a field name.
Change the field in the table named Date to something else, perhaps
"dteDdate".

See the appropriate Microsoft Knowledgebase article:
109312 'Reserved Words in Microsoft Access'
209187 'Acc2000: 'Reserved Words in Microsoft Access'
286335 'ACC2002: Reserved Words in Microsoft Access'

That may be all you need do.
The last line of your OnLoad code that I changed is
cboDate.Date = strRowsource

I get that compile error when I go from form desing to form view.

In the event you still get a compile error after changing the field
name, what line is it on?
Is the the line that uses the Date function?
strRowSource = strRowSource & Date + intX & "," <
If so, then you might also have a Missing reference.

Open any module in Design view (or click Ctrl + G).
On the Tools menu, click References.
Click to clear the check box for the type library or object library
marked as "Missing:."

An alternative to removing the reference is to restore the referenced
file to the path specified in the References dialog box. If the
referenced file is in a new location, clear the "Missing:" reference
and create a new reference to the file in its new folder.

See Microsoft KnowledgeBase articles:
283115 'ACC2002: References That You Must Set When You Work with
Microsoft Access'
Or for Access 97:
175484 'References to Set When Working With Microsoft Access' for
the correct ones needed,
and
160870 'VBA Functions Break in Database with Missing References' for
how to reset a missing one.

For even more information, see
http://members.rogers.com/douglas.j.steele/AccessReferenceErrors.html

Fred
 
Back
Top