need help with inserting a set of records

need help with inserting a set of records

am 13.04.2008 18:33:11 von mvdave

Hello all & I hope I'm posting in the right place..

I need to load a temporary table with a range of sequential dates,
passing it a beginning and an end date from a criteria form.

I have created the form FrmMakeDayFile with 2 unbound fields
[txtDateFr] and [TxtDateTo]. I simply want to be able to click a
button and have a routine of some sort append records to the table
tblDates with field Ddate inserted starting from txtDateFr and adding
a new record for each date, ending at TxtdateTo. (This data gets used
in a local front-end and is then zapped... but that part's under
control - I just need to quickly seed values to the dayfile table....)

I must be having a vague day as something that shoudld so easy is
eluding me... Can anybody start me off please.

thankyou.
Dave

Re: need help with inserting a set of records

am 13.04.2008 18:54:09 von Rick Brandt

mvdave wrote:
> Hello all & I hope I'm posting in the right place..
>
> I need to load a temporary table with a range of sequential dates,
> passing it a beginning and an end date from a criteria form.
>
> I have created the form FrmMakeDayFile with 2 unbound fields
> [txtDateFr] and [TxtDateTo]. I simply want to be able to click a
> button and have a routine of some sort append records to the table
> tblDates with field Ddate inserted starting from txtDateFr and adding
> a new record for each date, ending at TxtdateTo. (This data gets used
> in a local front-end and is then zapped... but that part's under
> control - I just need to quickly seed values to the dayfile table....)
>
> I must be having a vague day as something that shoudld so easy is
> eluding me... Can anybody start me off please.
>
> thankyou.
> Dave

Depends on what you already know how to do and what you don't. You need...

A VBA code procedure that opens an editable Recordset against your
destination table.

A Loop within that procedure.

Within the loop you create a date value one larger than the previous loop
iteration DateAdd() function being a good mechanism here.

Within that same loop you insert the generated date into your Recordset.

You start the loop with your start date and you stop the loop after you
have inserted the value matching your end date.

Which of the above do you already know how to do and which do you need help
with?

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

Re: need help with inserting a set of records

am 13.04.2008 19:09:44 von mvdave

On Apr 14, 2:54=A0am, "Rick Brandt" wrote:
> mvdave wrote:
> > Hello all & I hope I'm posting in the right place..
>
> > I need to load a temporary table with a range of sequential dates,
> > passing it a beginning and an end date from a criteria form.
>
> > I have created the form FrmMakeDayFile with 2 unbound fields
> > [txtDateFr] and [TxtDateTo]. I simply want to be able to click a
> > button and have a routine of some sort append records to the table
> > tblDates with field Ddate inserted starting from txtDateFr and adding
> > a new record for each date, ending at TxtdateTo. (This data gets used
> > in a local front-end and is then zapped... but that part's under
> > control - I just need to quickly seed values to the dayfile table....)
>
> > I must be having a vague day as something that shoudld so easy is
> > eluding me... =A0Can anybody start me off please.
>
> > thankyou.
> > Dave
>
> Depends on what you already know how to do and what you don't. =A0You need=
....
>
> A VBA code procedure that opens an editable Recordset against your
> destination table.
>
> A Loop within that procedure.
>
> Within the loop you create a date value one larger than the previous loop
> iteration DateAdd() function being a good mechanism here.
>
> Within that same loop you insert the generated date into your Recordset.
>
> You start the loop with your start date =A0and you stop the loop after you=

> have inserted the value matching your end date.
>
> Which of the above do you already know how to do and which do you need hel=
p
> with?
>
> --
> Rick Brandt, Microsoft Access MVP
> Email (as appropriate) to...
> RBrandt =A0 at =A0 Hunter =A0 dot =A0 com- Hide quoted text -
>
> - Show quoted text -

Thanks Rick... A programmer i ain't.. but here's where i got to with
it..which has elementrs of what you've advised. But it's not working..
I'm sure there's somthing simpler.

Dim sdate As Date
Dim edate As Date
Dim Ddate As Date

Dim rstDayfile As Recordset
Dim db As Database
Dim sqldates As String

Set db =3D CurrentDb()
sqldates =3D "select * from TblDates"
Set rstDayfile =3D db.OpenRecordset(sqldates, dbOpenDynaset)
sdate =3D Me.txtFromDate
edate =3D Me.txtToDate
Ddate =3D DMax("ddate", "tbldates")

With rstDayfile
Do Until Ddate > edate
Ddate =3D sdate
AddNew
!Ddate =3D sdate + 1
Update
Loop
End With

Re: need help with inserting a set of records

am 13.04.2008 19:24:54 von Salad

mvdave wrote:

> Hello all & I hope I'm posting in the right place..
>
> I need to load a temporary table with a range of sequential dates,
> passing it a beginning and an end date from a criteria form.
>
> I have created the form FrmMakeDayFile with 2 unbound fields
> [txtDateFr] and [TxtDateTo]. I simply want to be able to click a
> button and have a routine of some sort append records to the table
> tblDates with field Ddate inserted starting from txtDateFr and adding
> a new record for each date, ending at TxtdateTo. (This data gets used
> in a local front-end and is then zapped... but that part's under
> control - I just need to quickly seed values to the dayfile table....)
>
> I must be having a vague day as something that shoudld so easy is
> eluding me... Can anybody start me off please.
>
> thankyou.
> Dave

I might have a command button to initiate the append. Air code
Dim datFor As date
Dim rst As Recordset
set rst = Currentdb.openrecordset("TableName",dbopendynaset)
It Not IsNull(Me.FromDate) And Not IsNull(Me.ToDate) then
For datFor = Me.FromDate to Me.ToDate
rst.Addnew
rst!TableDateField = datFor
rst.Update
Next
Endif

Soon is now
http://www.youtube.com/watch?v=K2NrIALcNOw

Re: need help with inserting a set of records

am 13.04.2008 19:28:50 von Rick Brandt

mvdave wrote:
> On Apr 14, 2:54 am, "Rick Brandt" wrote:
>> mvdave wrote:
>>> Hello all & I hope I'm posting in the right place..
>>
>>> I need to load a temporary table with a range of sequential dates,
>>> passing it a beginning and an end date from a criteria form.
>>
>>> I have created the form FrmMakeDayFile with 2 unbound fields
>>> [txtDateFr] and [TxtDateTo]. I simply want to be able to click a
>>> button and have a routine of some sort append records to the table
>>> tblDates with field Ddate inserted starting from txtDateFr and
>>> adding a new record for each date, ending at TxtdateTo. (This data
>>> gets used in a local front-end and is then zapped... but that
>>> part's under control - I just need to quickly seed values to the
>>> dayfile table....)
>>
>>> I must be having a vague day as something that shoudld so easy is
>>> eluding me... Can anybody start me off please.
>>
>>> thankyou.
>>> Dave
>>
>> Depends on what you already know how to do and what you don't. You
>> need...
>>
>> A VBA code procedure that opens an editable Recordset against your
>> destination table.
>>
>> A Loop within that procedure.
>>
>> Within the loop you create a date value one larger than the previous
>> loop iteration DateAdd() function being a good mechanism here.
>>
>> Within that same loop you insert the generated date into your
>> Recordset.
>>
>> You start the loop with your start date and you stop the loop after
>> you have inserted the value matching your end date.
>>
>> Which of the above do you already know how to do and which do you
>> need help with?
>>
>> --
>> Rick Brandt, Microsoft Access MVP
>> Email (as appropriate) to...
>> RBrandt at Hunter dot com- Hide quoted text -
>>
>> - Show quoted text -
>
> Thanks Rick... A programmer i ain't.. but here's where i got to with
> it..which has elementrs of what you've advised. But it's not working..
> I'm sure there's somthing simpler.
>
> Dim sdate As Date
> Dim edate As Date
> Dim Ddate As Date
>
> Dim rstDayfile As Recordset
> Dim db As Database
> Dim sqldates As String
>
> Set db = CurrentDb()
> sqldates = "select * from TblDates"
> Set rstDayfile = db.OpenRecordset(sqldates, dbOpenDynaset)
> sdate = Me.txtFromDate
> edate = Me.txtToDate
> Ddate = DMax("ddate", "tbldates")
>
> With rstDayfile
> Do Until Ddate > edate
> Ddate = sdate
> AddNew
> !Ddate = sdate + 1
> Update
> Loop
> End With

Try...

Dim edate As Date
Dim NewDate As Date
Dim rstDayfile As Recordset
Dim db As Database
Dim sqldates As String

Set db = CurrentDb()
sqldates = "select * from TblDates"
Set rstDayfile = db.OpenRecordset(sqldates, dbOpenDynaset)
NewDate = Me.txtFromDate
edate = Me.txtToDate

With rstDayfile
Do Until NewDate > edate
.AddNew
!Ddate = NewDate
.Update
NewDate = DateAdd("d", 1, NewDate)
Loop
End With



--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

Re: need help with inserting a set of records

am 13.04.2008 19:41:33 von mvdave

On Apr 14, 3:24=A0am, Salad wrote:
> mvdave wrote:
> > Hello all & I hope I'm posting in the right place..
>
> > I need to load a temporary table with a range of sequential dates,
> > passing it a beginning and an end date from a criteria form.
>
> > I have created the form FrmMakeDayFile with 2 unbound fields
> > [txtDateFr] and [TxtDateTo]. I simply want to be able to click a
> > button and have a routine of some sort append records to the table
> > tblDates with field Ddate inserted starting from txtDateFr and adding
> > a new record for each date, ending at TxtdateTo. (This data gets used
> > in a local front-end and is then zapped... but that part's under
> > control - I just need to quickly seed values to the dayfile table....)
>
> > I must be having a vague day as something that shoudld so easy is
> > eluding me... =A0Can anybody start me off please.
>
> > thankyou.
> > Dave
>
> I might have a command button to initiate the append. =A0Air code
> =A0 =A0 =A0 =A0 Dim datFor As date
> =A0 =A0 =A0 =A0 Dim rst As Recordset
> =A0 =A0 =A0 =A0 set rst =3D Currentdb.openrecordset("TableName",dbopendyna=
set)
> =A0 =A0 =A0 =A0 It Not IsNull(Me.FromDate) And Not IsNull(Me.ToDate) then
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 For datFor =3D Me.FromDate to Me.ToDate
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rst.Addnew
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rst!TableDateField =3D dat=
For
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 rst.Update
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Next
> =A0 =A0 =A0 =A0 Endif
>
> Soon is nowhttp://www.youtube.com/watch?v=3DK2NrIALcNOw- Hide quoted text =
-
>
> - Show quoted text -

OK - thankyou Salad!!

Here' the tidied version of your air code... Worked a treat! Thankyou
very much. It's 3:40 am here... time for some zzzzz's. Much
appreciated. Dave.

Private Sub CmdMakeDayFile_Click()

Dim datFor As Date
Dim rst As Recordset

Set rst =3D CurrentDb.OpenRecordset("tblDates", dbOpenDynaset)

If Not IsNull(Me.txtFromDate) And Not IsNull(Me.txtToDate) Then
For datFor =3D Me.txtFromDate To Me.txtToDate
rst.AddNew
rst!Ddate =3D datFor
rst.Update
Next
End If

End Sub

Re: need help with inserting a set of records

am 13.04.2008 20:00:07 von fredg

On Sun, 13 Apr 2008 09:33:11 -0700 (PDT), mvdave wrote:

> Hello all & I hope I'm posting in the right place..
>
> I need to load a temporary table with a range of sequential dates,
> passing it a beginning and an end date from a criteria form.
>
> I have created the form FrmMakeDayFile with 2 unbound fields
> [txtDateFr] and [TxtDateTo]. I simply want to be able to click a
> button and have a routine of some sort append records to the table
> tblDates with field Ddate inserted starting from txtDateFr and adding
> a new record for each date, ending at TxtdateTo. (This data gets used
> in a local front-end and is then zapped... but that part's under
> control - I just need to quickly seed values to the dayfile table....)
>
> I must be having a vague day as something that shoudld so easy is
> eluding me... Can anybody start me off please.
>
> thankyou.
> Dave



Copy and paste the below code into a Module.
Open your form and enter the 2 dates.
Run the Code.

Public Sub FillDates()
' Will fill a Date Field with consecutive date values.

Dim db As DAO.Database
Dim rs As Recordset
Dim dteFrom As Date
Dim dteTo As Date
Set db = CurrentDb
Set rs = db.OpenRecordset("tblDates")
dteFrom = Forms!FrmMakeDayFile![txtDateFr]
dteTo = Forms!FrmMakeDayFile![txtDateTo]

With rs
Do Until dteFrom = dteTo + 1
.AddNew
!Ddate = dteFrom
.Update
dteFrom = dteFrom + 1
Loop
End With
Set db = Nothing
Set rs = Nothing
End Sub
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

Re: need help with inserting a set of records

am 13.04.2008 20:25:40 von Salad

mvdave wrote:

> On Apr 14, 3:24 am, Salad wrote:
>
>>mvdave wrote:
>>
>>>Hello all & I hope I'm posting in the right place..
>>
>>>I need to load a temporary table with a range of sequential dates,
>>>passing it a beginning and an end date from a criteria form.
>>
>>>I have created the form FrmMakeDayFile with 2 unbound fields
>>>[txtDateFr] and [TxtDateTo]. I simply want to be able to click a
>>>button and have a routine of some sort append records to the table
>>>tblDates with field Ddate inserted starting from txtDateFr and adding
>>>a new record for each date, ending at TxtdateTo. (This data gets used
>>>in a local front-end and is then zapped... but that part's under
>>>control - I just need to quickly seed values to the dayfile table....)
>>
>>>I must be having a vague day as something that shoudld so easy is
>>>eluding me... Can anybody start me off please.
>>
>>>thankyou.
>>>Dave
>>
>>I might have a command button to initiate the append. Air code
>> Dim datFor As date
>> Dim rst As Recordset
>> set rst = Currentdb.openrecordset("TableName",dbopendynaset)
>> It Not IsNull(Me.FromDate) And Not IsNull(Me.ToDate) then
>> For datFor = Me.FromDate to Me.ToDate
>> rst.Addnew
>> rst!TableDateField = datFor
>> rst.Update
>> Next
>> Endif
>>
>>Soon is nowhttp://www.youtube.com/watch?v=K2NrIALcNOw- Hide quoted text -
>>
>>- Show quoted text -
>
>
> OK - thankyou Salad!!
>
> Here' the tidied version of your air code... Worked a treat! Thankyou
> very much. It's 3:40 am here... time for some zzzzz's. Much
> appreciated. Dave.

It appears you are a bit aways from the US. Australia?

I think you can either go to bed now or get up for the Monday commute.

>
> Private Sub CmdMakeDayFile_Click()
>
> Dim datFor As Date
> Dim rst As Recordset
>
> Set rst = CurrentDb.OpenRecordset("tblDates", dbOpenDynaset)
>
> If Not IsNull(Me.txtFromDate) And Not IsNull(Me.txtToDate) Then
> For datFor = Me.txtFromDate To Me.txtToDate
> rst.AddNew
> rst!Ddate = datFor
> rst.Update
> Next
> End If
>
> End Sub

Re: need help with inserting a set of records

am 13.04.2008 23:48:11 von mvdave

On Apr 14, 4:25=A0am, Salad wrote:
> mvdave wrote:
> > On Apr 14, 3:24 am, Salad wrote:
>
> >>mvdave wrote:
>
> >>>Hello all & I hope I'm posting in the right place..
>
> >>>I need to load a temporary table with a range of sequential dates,
> >>>passing it a beginning and an end date from a criteria form.
>
> >>>I have created the form FrmMakeDayFile with 2 unbound fields
> >>>[txtDateFr] and [TxtDateTo]. I simply want to be able to click a
> >>>button and have a routine of some sort append records to the table
> >>>tblDates with field Ddate inserted starting from txtDateFr and adding
> >>>a new record for each date, ending at TxtdateTo. (This data gets used
> >>>in a local front-end and is then zapped... but that part's under
> >>>control - I just need to quickly seed values to the dayfile table....)
>
> >>>I must be having a vague day as something that shoudld so easy is
> >>>eluding me... =A0Can anybody start me off please.
>
> >>>thankyou.
> >>>Dave
>
> >>I might have a command button to initiate the append. =A0Air code
> >> =A0 =A0 =A0 =A0Dim datFor As date
> >> =A0 =A0 =A0 =A0Dim rst As Recordset
> >> =A0 =A0 =A0 =A0set rst =3D Currentdb.openrecordset("TableName",dbopendy=
naset)
> >> =A0 =A0 =A0 =A0It Not IsNull(Me.FromDate) And Not IsNull(Me.ToDate) the=
n
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0For datFor =3D Me.FromDate to Me.ToDate
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0rst.Addnew
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0rst!TableDateField =3D d=
atFor
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0rst.Update
> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Next
> >> =A0 =A0 =A0 =A0Endif
>
> >>Soon is nowhttp://www.youtube.com/watch?v=3DK2NrIALcNOw-Hide quoted text=
-
>
> >>- Show quoted text -
>
> > OK - thankyou Salad!!
>
> > Here' the tidied version of your air code... Worked a treat! Thankyou
> > very much. It's 3:40 am here... time for some zzzzz's. Much
> > appreciated. Dave.
>
> It appears you are a bit aways from the US. =A0Australia?
>
> I think you can either go to bed now or get up for the Monday commute.
>
>
>
>
>
> > Private Sub CmdMakeDayFile_Click()
>
> > Dim datFor As Date
> > Dim rst As Recordset
>
> > Set rst =3D CurrentDb.OpenRecordset("tblDates", dbOpenDynaset)
>
> > If Not IsNull(Me.txtFromDate) And Not IsNull(Me.txtToDate) Then
> > =A0 =A0 For datFor =3D Me.txtFromDate To Me.txtToDate
> > =A0 =A0 =A0 =A0 rst.AddNew
> > =A0 =A0 =A0 =A0 rst!Ddate =3D datFor
> > =A0 =A0 =A0 =A0 rst.Update
> > =A0 =A0 Next
> > End If
>
> > End Sub- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Yes, I'm in Sydney and thankyou to all for your quick and varied
suggestions. I've tried posting on other help forums before and gone
days without a response, so I really appreciate the way you've all
jumped in and helped.

Now.. I owe I owe... so off to work i go..

Dave