PC Review


Reply
Thread Tools Rate Thread

Auto Generating Records in Table

 
 
=?Utf-8?B?TWVpcmF2?=
Guest
Posts: n/a
 
      14th Jun 2005
I have a table tblWeek with the following fields:
WeekID (AutoNum)
Mon (Date Field)
Tue (Date Field)
Wed (Date Field)
..
..
..
Sun (Date Field)

I would like to have a form with the following parameters:
txtNumberOfWeeks (Number)
txtFromMonDate (Date)

And have a button that when pushed, a program will create records in my
tblWeek for the number of weeks asked and populate the dates from the
txtFromMonDate onwards.

For Example:
txtNumberOfWeeks (Number) = 3
txtFromMonDate (Date) = 06/20/2005

Will create:

WeekIDNo Mon Tue Wed Thu Fri Sat Sun
====== === === === === === === ===
<next no> 06/20/2005 06/21/2005 06/22/2005 ... ... ... 06/26/2005
<next no> 06/27/2005 06/28/2005 06/29/2005 ... ... ... 07/03/2005
<next no> 07/04/2005 07/05/2005 07/06/2005 ... ... ... 07/10/2005

Any Ideas?
 
Reply With Quote
 
 
 
 
Tim Ferguson
Guest
Posts: n/a
 
      15th Jun 2005
=?Utf-8?B?TWVpcmF2?= <(E-Mail Removed)> wrote in
news:797F8557-02CC-4653-BB02-(E-Mail Removed):

> And have a button that when pushed, a program will create records in
> my tblWeek for the number of weeks asked and populate the dates from
> the txtFromMonDate onwards.
>
> Any Ideas?
>


Do it in Excel. As stated, this is a spreadsheet question, not a database
one. There is virtually never any need to create dummy empty records; and
never ever ever ever ever ever any need to create fields like MondayDate,
TuesdayDate, WednesdayDate and so on.

What is the problem that this solution is meant to solve?

B wishes


Tim F

 
Reply With Quote
 
laudus
Guest
Posts: n/a
 
      16th Jun 2005
Function Add_Dates(lngWeekCnt As Long, dteStartDate As Date

Dim rst As ADODB.Recordse
Dim lngAdd_Week As Lon
Dim lngCount As Lon

'Optional check to make sure that the dat
'that was entered is a Monda
If DatePart("w", dteStartDate) <> 2 The
D
dteStartDate = InputBox("The date you entered is not
Monday." &
Chr(10) & "Please enter a date that is a Monday."
Loop Until DatePart("w", dteStartDate) =
End I

Set rst = New ADODB.Recordse
Set rst.ActiveConnection = CurrentProject.Connectio
rst.CursorType = adOpenDynami
rst.LockType = adLockOptimisti
rst.Open "tblWeek

'In case someone enters a zer
If lngWeekCnt = 0 Then Exit Functio

For lngCount = 1 To lngWeekCn
With rs
.AddNe
.Fields(1) = dteStartDat
.Fields(2) = dteStartDate +
.Fields(3) = dteStartDate +
.Fields(4) = dteStartDate +
.Fields(5) = dteStartDate +
.Fields(6) = dteStartDate +
.Fields(7) = dteStartDate +
.Updat
End Wit
dteStartDate = dteStartDate +
Nex
rst.Clos
Set rst = Nothin

End Functio

It worked for me. Hope it helps

Erik Spark

 
Reply With Quote
 
=?Utf-8?B?TWVpcmF2?=
Guest
Posts: n/a
 
      16th Jun 2005
It is part of the design, the reasons are complicated

It was actually a question of VB Programming (not excel since I am using an
ACCESS database), but I was able to do it...

Just created a module that does the work

Thanks for the answer though...


"Tim Ferguson" wrote:

> =?Utf-8?B?TWVpcmF2?= <(E-Mail Removed)> wrote in
> news:797F8557-02CC-4653-BB02-(E-Mail Removed):
>
> > And have a button that when pushed, a program will create records in
> > my tblWeek for the number of weeks asked and populate the dates from
> > the txtFromMonDate onwards.
> >
> > Any Ideas?
> >

>
> Do it in Excel. As stated, this is a spreadsheet question, not a database
> one. There is virtually never any need to create dummy empty records; and
> never ever ever ever ever ever any need to create fields like MondayDate,
> TuesdayDate, WednesdayDate and so on.
>
> What is the problem that this solution is meant to solve?
>
> B wishes
>
>
> Tim F
>
>

 
Reply With Quote
 
=?Utf-8?B?TWVpcmF2?=
Guest
Posts: n/a
 
      16th Jun 2005
It DOES! Thanks

"laudus" wrote:

> Function Add_Dates(lngWeekCnt As Long, dteStartDate As Date)
>
> Dim rst As ADODB.Recordset
> Dim lngAdd_Week As Long
> Dim lngCount As Long
>
> 'Optional check to make sure that the date
> 'that was entered is a Monday
> If DatePart("w", dteStartDate) <> 2 Then
> Do
> dteStartDate = InputBox("The date you entered is not a
> Monday." & _
> Chr(10) & "Please enter a date that is a Monday.")
> Loop Until DatePart("w", dteStartDate) = 2
> End If
>
> Set rst = New ADODB.Recordset
> Set rst.ActiveConnection = CurrentProject.Connection
> rst.CursorType = adOpenDynamic
> rst.LockType = adLockOptimistic
> rst.Open "tblWeek"
>
> 'In case someone enters a zero
> If lngWeekCnt = 0 Then Exit Function
>
> For lngCount = 1 To lngWeekCnt
> With rst
> .AddNew
> .Fields(1) = dteStartDate
> .Fields(2) = dteStartDate + 1
> .Fields(3) = dteStartDate + 2
> .Fields(4) = dteStartDate + 3
> .Fields(5) = dteStartDate + 4
> .Fields(6) = dteStartDate + 5
> .Fields(7) = dteStartDate + 6
> .Update
> End With
> dteStartDate = dteStartDate + 7
> Next
> rst.Close
> Set rst = Nothing
>
> End Function
>
> It worked for me. Hope it helps.
>
> Erik Sparks
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
auto-numbering records in a sub-table =?Utf-8?B?QW5uZXR0ZQ==?= Microsoft Access 4 5th Apr 2006 11:54 AM
Auto-generating a list of records that meet a pattern criteria =?Utf-8?B?SmVmZiBHZXJrZQ==?= Microsoft Excel Misc 0 23rd Mar 2006 11:18 PM
generating a table's default records and moving to a new one =?Utf-8?B?a3Jpcw==?= Microsoft Access Forms 0 21st Nov 2005 08:23 PM
Generating an Auto Number ID Field in a Make Table Query mcl Microsoft Access Queries 5 7th Apr 2005 05:02 AM
Form generating records from tables and manual entry plus validating from a table???? Joseph Microsoft Access Form Coding 0 30th Jul 2003 07:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:36 PM.