473,472 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Add records programmatically?

I need to write consecutive dates to a table, starting with a date
input on a form. I haven't got a clue as to where to begin.
I have searcewd the web with no success. Could someone help at least
get me started?

Thanks for any help

Nov 13 '05 #1
3 3310
This should add 10 years worth of dates to tblDate.TheDate:

Function MakeDates()
Dim dt As Date
Dim rs As DAO.Recordset

Set rs = DBEngine(0)(0).OpenRecordset("tblDate")
With rs
For dt = #1/1/2004# To #12/31/2013#
.AddNew
!TheDate = dt
.Update
Next
End With
rs.Close
Set rs = Nothing
End Function
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Shyguy" <sh****@aol.com> wrote in message
news:e0********************************@4ax.com...
I need to write consecutive dates to a table, starting with a date
input on a form. I haven't got a clue as to where to begin.
I have searcewd the web with no success. Could someone help at least
get me started?

Thanks for any help

Nov 13 '05 #2
On Sat, 26 Jun 2004 02:18:24 GMT, Shyguy <sh****@aol.com> wrote:
I need to write consecutive dates to a table, starting with a date
input on a form. I haven't got a clue as to where to begin.
I have searcewd the web with no success. Could someone help at least
get me started?

Thanks for any help


This should get you going.

Put a textbox on the input form to store the start date and change DateInputTextboxName in the code to the name of the
textbox.

Add a command button to the form and in it's property sheet set OnClick to [Event Procedure] then click on the "..."
button at the right of the property to open the code module.
Paste the following code between the Sub and End Sub lines and change MyDateField and tblMyTable to your field / table
names as required.

When they click the button the records are written to the table.

** Untested air code so keep backup before using

'******Code Start*******
Dim strSQL as String
Dim db as Database
Dim rst as DAO.Recordset
Dim dtStartDate As Date
Dim intNoOfDates As Integer
Dim i As Integer

On Error GoTo HandleIt

If Not IsNull(Me.DateInputTextboxName) Then
strSQL = "SELECT MyDateField FROM tblMytable;
Set db = CurrentDB()
Set rst = db.OpenRecordset(strSQL,dbOpenDynaset,dbAppendOnly )

dtStartDate = Me.DateInputTextboxName
intNoOfDates = 999 'change to required number of dates

With rst
'add start date
.Addnew
!MyDateField = dtStartDate
.Update

'now add required dates
For i = 1 To intNoOfDates - 1
.AddNew
!MyDateField = DateAdd("d", i, dtStartDate)
.Update
Next i
.Close
End With
End If

MsgBox "Dates added to table", vbInformation + vbOKOnly, "Success"

OutHere:
If Not (rst Is Nothing) Then Set rst = Nothing
If Not (db Is Nothing) Then Set db = Nothing
Exit Sub

HandleIt:
MsgBox "Operation Failed", vbCritical + vbOKOnly, "Bummer"
Resume OutHere
'******Code End*******

Wayne Gillespie
Gosford NSW Australia
Nov 13 '05 #3
On Sat, 26 Jun 2004 05:57:20 GMT, Wayne Gillespie
<be*****@NObestfitsoftwareSPAM.com.au> wrote:
On Sat, 26 Jun 2004 02:18:24 GMT, Shyguy <sh****@aol.com> wrote:
I need to write consecutive dates to a table, starting with a date
input on a form. I haven't got a clue as to where to begin.
I have searcewd the web with no success. Could someone help at least
get me started?

Thanks for any help


This should get you going.

Put a textbox on the input form to store the start date and change DateInputTextboxName in the code to the name of the
textbox.

Add a command button to the form and in it's property sheet set OnClick to [Event Procedure] then click on the "..."
button at the right of the property to open the code module.
Paste the following code between the Sub and End Sub lines and change MyDateField and tblMyTable to your field / table
names as required.

When they click the button the records are written to the table.

** Untested air code so keep backup before using

'******Code Start*******
Dim strSQL as String
Dim db as Database
Dim rst as DAO.Recordset
Dim dtStartDate As Date
Dim intNoOfDates As Integer
Dim i As Integer

On Error GoTo HandleIt

If Not IsNull(Me.DateInputTextboxName) Then
strSQL = "SELECT MyDateField FROM tblMytable;
Set db = CurrentDB()
Set rst = db.OpenRecordset(strSQL,dbOpenDynaset,dbAppendOnly )

dtStartDate = Me.DateInputTextboxName
intNoOfDates = 999 'change to required number of dates

With rst
'add start date
.Addnew
!MyDateField = dtStartDate
.Update

'now add required dates
For i = 1 To intNoOfDates - 1
.AddNew
!MyDateField = DateAdd("d", i, dtStartDate)
.Update
Next i
.Close
End With
End If

MsgBox "Dates added to table", vbInformation + vbOKOnly, "Success"

OutHere:
If Not (rst Is Nothing) Then Set rst = Nothing
If Not (db Is Nothing) Then Set db = Nothing
Exit Sub

HandleIt:
MsgBox "Operation Failed", vbCritical + vbOKOnly, "Bummer"
Resume OutHere
'******Code End*******

Wayne Gillespie
Gosford NSW Australia


Thank you very much. This worked perfectly. I neglected to say that
some days had to be added twice but I worked that out with a query and
the table is created with the dates I need.

Thanks again

Nov 13 '05 #4

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

Similar topics

1
by: Rebecca | last post by:
I have an Access97 front end using ODBC to communicate with an SQLServer 7.0 back end on a different machine. Most of the work I do in the front end uses forms bound to linked tables that reside...
1
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
1
by: STeve Lefevre | last post by:
Is there a way to make a query that shows records that do not appear in a recordset? I'm concerned with two tables: tblQuestions and tblTemplateQuestions. tblTemplateQuestions is a merge table...
2
by: John Baker | last post by:
Hi: I have a Pop Up form that involves a main form and sub form. The sub form has the results of a query on the main form. I need to automatically perform exactly he same action that takes...
7
by: Trevor Best | last post by:
I have an import routine that takes a generic file (Excel, CSV, Fixed length, PDMS BOM, XML, etc) and maps fields to a temp import table on the server, in the field mapping there may be functions...
2
by: origin197511 | last post by:
Hello all... I'm having an issue with MSAccess 2000. I have a Form that holds records of my cartridge loads for a rifle and a subform that lists all groups that have been fired with that load. ...
1
by: John M | last post by:
I can open a form using a combo box to select a group of records. stLinkCriteria = "= '" & Me! & "'" DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria is what comes from the combo box....
10
by: Thelma Lubkin | last post by:
My form/subform combination that allows user to display 'ColorSet' records, move to other records via a selector, to add,delete, and edit them, and to manage the related 'Color' records from the...
4
by: ske | last post by:
Hi I've inherited an Access database where there is a form setup which prints out a Job Sheet. This works fine with one record. However I need to set it to loop through several records and print...
7
by: lmeyers | last post by:
I implemented a URL rewriter which worked reasonably well, but now I am creating other sites on the same server (single IP). Because IIS will not accept subdomain wildcards (*.subdomain.com), it...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.