473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Creating values in a table in code

Hi,

I have a table with 2 fields - flddate and category.

The values of flddate are all working day dates (monday to friday
dates between jan 2007 and 2010 (although the end date could change).

I would like to write code to insert the numbers 1 to 6 in repetition
into the category field until every row is filled.

For example I would like the finished table to be;

flddate category
1/jan/07 1
2/jan/07 2
3/jan/07 3
4/jan/07 4
5/jan/07 5
8/jan/07 6
9/jan/07 1
10/jan/.07 2

etc, etc. As I said the flddate values are already completed.

Any help or where to start is appreciated. Thanks,

Mar 24 '07 #1
5 1504
On Mar 24, 10:28 am, "keri" <keridow...@hotmail.comwrote:
Hi,

I have a table with 2 fields - flddate and category.

The values of flddate are all working day dates (monday to friday
dates between jan 2007 and 2010 (although the end date could change).

I would like to write code to insert the numbers 1 to 6 in repetition
into the category field until every row is filled.

For example I would like the finished table to be;

flddate category
1/jan/07 1
2/jan/07 2
3/jan/07 3
4/jan/07 4
5/jan/07 5
8/jan/07 6
9/jan/07 1
10/jan/.07 2

etc, etc. As I said the flddate values are already completed.

Any help or where to start is appreciated. Thanks,
I can't imagine why you want that rather than day of week, but ...

dim db as dao.database, r as dao.recordset
Dim i as integer

set db=currentdb
set r=db.openrecordset ("Select * from table ORDER BY flddate;",
dbopendynaset)
i = 1
do while not r.eof
r.edit
r!Category = i
r.update
i = i + 1
if (i 6) then i=1
r.movenext
end do
r.close
set r=nothing
set db=nothing

This is one way and it's simple.

-- Larry Engles
Mar 24 '07 #2
Larry,

Many thanks for the above. I presume by the day of the week comment
you are referring to Mon being a 1 and Tue being a 2 etc etc, in which
case me needing 6 numbers on Mon - Fri wouldn't work. However if I am
missing the point please correct me as I may be making this difficult
for myself!

Anyway the code is super, thanks,

Mar 24 '07 #3
Hi Keri,
Have you looked at the Weekday() function?
Weekday(date, [firstdayofweek])
You can set the "firstdayofweek" to 2, and it should display the results you
want.

"keri" <ke********@hotmail.comwrote in message
news:11*********************@d57g2000hsg.googlegro ups.com...
Larry,

Many thanks for the above. I presume by the day of the week comment
you are referring to Mon being a 1 and Tue being a 2 etc etc, in which
case me needing 6 numbers on Mon - Fri wouldn't work. However if I am
missing the point please correct me as I may be making this difficult
for myself!

Anyway the code is super, thanks,

Mar 25 '07 #4
Sorry Keri ... I hadn't absorbed what you had said. You want to populate a
table with these values, not use existing data ... right?

If this is the case, then I believe that Larry's code won't do the job
either ... he too is attempting to work with existing data.

Let me ponder on this for a while, and I'll post some new code.

Don.
"Don Leverton" <le****************@telusplanet.netwrote in message
news:4pyNh.17719$x9.2041@edtnps89...
Hi Keri,
Have you looked at the Weekday() function?
Weekday(date, [firstdayofweek])
You can set the "firstdayofweek" to 2, and it should display the results
you
want.

"keri" <ke********@hotmail.comwrote in message
news:11*********************@d57g2000hsg.googlegro ups.com...
Larry,

Many thanks for the above. I presume by the day of the week comment
you are referring to Mon being a 1 and Tue being a 2 etc etc, in which
case me needing 6 numbers on Mon - Fri wouldn't work. However if I am
missing the point please correct me as I may be making this difficult
for myself!

Anyway the code is super, thanks,


Mar 25 '07 #5
Ok Keri, try this:

Using Access97, I created an unbound form that contains:
=======================================
A calendar control ("MyCalendar")
2 un-bound text-boxes ("txtStartDate" and "txtEndDate") both "Enabled", but
"Locked", and formatted "Short Date".
(This forces the user to use the calendar control to set the dates ... which
WILL be formatted correctly.)

A Command Button ("cmdAddRecords")
A subform ("sbfFldDate") which is linked to the table ("tblFldDates")

Also... "flddate" in tblFldDates is indexed, Allow duplicates = No
This provision is so that you can not accidentally duplicate existing
entries, yet still allows newer dates.
(ie. if you entered a start date of "01/01/2007" again and changed the end
date to "01/01/2011", it wil not duplicate (Errorcode 3022) the 2007 to 2010
dates , but it WILL add records from 01/02/2010 to 01/01/2011.)
=======================================

Here is the entire code that drives this operation.

=======================================
Option Compare Database
Option Explicit
Dim ctl As Variant
Dim MyStartDate As Date
Dim MyDate As Date
Dim MyEndDate As Date
Dim MyCategory

Private Sub cmdAddRecords_Click()
On Error GoTo ErrHandler

Dim rstAddDates As DAO.Recordset
Set rstAddDates = Me.sbfFldDate.Form.RecordsetClone
MyStartDate = Me.txtStartDate
MyEndDate = Me.txtEndDate

'Let's make sure we have a Start Date and an End Date before proceeding.
If IsDate(MyStartDate) And IsDate(MyEndDate) Then

With rstAddDates ' Doing this will save us a bunch of typing.
'Add the initial values
.AddNew
!flddate = MyStartDate
MyDate = MyStartDate
MyCategory = WeekDay(MyDate, vbMonday)
!Category = MyCategory
.Update

Do Until MyDate = MyEndDate 'Set up a Loop that will continue until
we want it to end.
MyDate = DateAdd("d", 1, MyDate) 'Now add one day at a time
MyCategory = WeekDay(MyDate, vbMonday) 'Gets a "day of week
value"(1 to 5) for the date

If MyCategory 0 And MyCategory < 6 Then 'We only want to
add values 1 thru 5
.AddNew 'This adds the data into the subform's
recordset.
!flddate = MyDate
!Category = MyCategory
.Update
.Bookmark = .LastModified
Me.sbfFldDate.Form.Bookmark = .Bookmark 'This will show
the new records as they are created.
End If

Loop

.Close

End With
Set rstAddDates = Nothing 'Release the recordset object

Else

MsgBox ("Please make sure that both Start and End Dates are provided.")

End If

ErrHandler:
If Err.Number = 3022 Then
Resume Next
Else
Dim Msg
Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox Msg, , "Error"
Exit Sub
End If

End Sub

Private Sub MyCalendar_AfterUpdate()
Select Case ctl
Case 1
Me.txtStartDate.SetFocus
Me![txtStartDate] = Me![MyCalendar]
MyStartDate = Me![MyCalendar]

Case 2
Me.txtEndDate.SetFocus
Me![txtEndDate] = Me![MyCalendar]
MyEndDate = Me![MyCalendar]
Case Else

Exit Sub
End Select
End Sub
Private Sub txtStartDate_Enter()
ctl = 1

End Sub

Private Sub txtEndDate_Enter()
ctl = 2

End Sub

Private Sub txtStartDate_KeyDown(KeyCode As Integer, Shift As Integer)
ctl = 1
MsgBox ("Please Select a date from the Calendar.")
Me.MyCalendar.SetFocus
Me![txtStartDate] = Me.MyCalendar
End Sub

Private Sub txtEndDate_KeyDown(KeyCode As Integer, Shift As Integer)
ctl = 2
MsgBox ("Please Select a date from the Calendar.")
Me.MyCalendar.SetFocus
Me![txtEndDate] = Me.MyCalendar

End Sub
I have tested this, and found that it does what I think you are trying to
do.
HTH,
Don
"Don Leverton" <le****************@telusplanet.netwrote in message
news:xwyNh.17747$x9.101@edtnps89...
Sorry Keri ... I hadn't absorbed what you had said. You want to populate a
table with these values, not use existing data ... right?

If this is the case, then I believe that Larry's code won't do the job
either ... he too is attempting to work with existing data.

Let me ponder on this for a while, and I'll post some new code.

Don.
"Don Leverton" <le****************@telusplanet.netwrote in message
news:4pyNh.17719$x9.2041@edtnps89...
Hi Keri,
Have you looked at the Weekday() function?
Weekday(date, [firstdayofweek])
You can set the "firstdayofweek" to 2, and it should display the results
you
want.

"keri" <ke********@hotmail.comwrote in message
news:11*********************@d57g2000hsg.googlegro ups.com...
Larry,
>
Many thanks for the above. I presume by the day of the week comment
you are referring to Mon being a 1 and Tue being a 2 etc etc, in which
case me needing 6 numbers on Mon - Fri wouldn't work. However if I am
missing the point please correct me as I may be making this difficult
for myself!
>
Anyway the code is super, thanks,
>


Mar 25 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Indraneel Sheorey | last post by:
Hello, I want to set up a query in SQL Server that is "grouped by" a variable PRICE. Since PRICE takes on continuous decimal values, I want to create deciles based on this variable and then...
4
by: gonzal | last post by:
Hi Dose any body know why a temporary table gets deleted after querying it the first time (using SELECT INTO)? When I run the code bellow I'm getting an error message when open the temp table...
7
by: John Baker | last post by:
Hi: I would like to know how to create a temp DB to store the data in a table while I do something else with the table. Specifically, how do I create the temp remove the temp I want to be...
13
by: Nagib Abi Fadel | last post by:
Is it possible to create a session variable for each user in Postresql ?? Thx
7
by: rcamarda | last post by:
I wish to build a table based on values from another table. I need to populate a table between two dates from another table. Using the START_DT and END_DT, create records between those dates. I...
3
by: Bhavsan | last post by:
Here is what I am trying to do. Kindly, help me. 1. I'm creating a query dynamically based on User input using VBA (strSQL and DotSQL in the code below) 2. Executing the created query with in VBA...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
1
newnewbie
by: newnewbie | last post by:
Desperately need help in creating a query to count unique values in a table. I am a Business analyst with limited knowledge of Access….My boss got me ODBC connection to the underlying tables for our...
2
by: astolpho | last post by:
I am using a slightly outdated reference book on J2EE programming. It gives 2 methods of creating a database used in its casestudies. The first is an ANT script that gives the following output: ...
22
kcdoell
by: kcdoell | last post by:
I have been trying for the last several days to create a query that will give me all of the values I need to create a report. Background: The report is different than anything I have done but...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.