View Single Post
  #4  
Old May 12th, 2010, 11:33 PM posted to microsoft.public.access.forms
Flopbot
external usenet poster
 
Posts: 60
Default Add consecutive dates w/ command button & parameter boxes

Thank you Groeten & Karl for sharing your knowledge of Access with others!

I’m playing around with Groeten’s suggestion (since his was first) and I
think it’s definitely in line with what I’m looking for (although it didn’t
work). I did some more searching on the forums and found something about
InputBoxes which sounds ideal. I tried one and it popped up a box to enter
my date. Since I don’t know code, I’m sure I’ve butchered the following (it
doesn’t work), but am I at all close?


Private Sub Add_One_Month_DblClick()

Dim EventCount As Byte
Dim StartDate As String

StartDate = InputBox("Please Select a StartDate", "CUSTOMER SELECTION")
For EventCount = 1 To 31
DoCmd.RunSQL "INSERT INTO [SubFrm Vol Opportunities] (Event Date)
VALUES(#" & DateAdd("m", EventCount - 1, [StartDate]) & "#)"
Next

End Sub


"XPS35" wrote:

=?Utf-8?B?RmxvcGJvdA==?= wrote:


Hi,

I have an unbound form [Frm Volunteer Opportunities] with a sub form [SubFrm
Vol Opportunities]. The subform has the fields [Event ID] and [Event Date].
My unbound form has a command button on it.

Basically, what I’m trying to do is have Access automatically create 31 new
records in [SubFrm Vol Opportunities] whenever I click the button. I want
each new record to be dated 5/1/2010, 5/2/2010, 5/3/2010, and so on starting
and ending with the dates that I provide in pop-up parameter boxes.
Unfortunately, I don't know code although I can probably figure out where to
cut/paste it.

Yes, I will use each new record. This will greatly decrease the amount of
time spent entering data since I would typically be doing it every single
month.

Thank you for your help!


A code for this could look like:

Dim EventCount As Byte

For EventCount = 1 To 31
DoCmd.RunSQL "INSERT INTO YourTable (EventDate) VALUES(#" & _
DateAdd("m", EventCount - 1, Me.StartDate) & "#)"
Next

I use an unbound field (Me.StartDate) as input.

--
Groeten,

Peter
http://access.xps350.com

.