473,386 Members | 1,754 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,386 software developers and data experts.

Automatically create records

Hi all,
What I am trying to achieve is for a user to enter a colleague
identification number into field [ID]. Then they are to add the first date
of holiday into field [f_date]. Finally they are to add the number of days
into an unbound text box [days]. Once a command is fired, I would like to be
able to add records into tbl_holidays. One for each date the person has
recorded.

e.g.
Input form:

ID f_date Days
10089654 16/11/2004 5

records to be added into table after closure of form:

ID booked_hols
10089654 16/11/2004
10089654 17/11/2004
10089654 18/11/2004
10089654 19/11/2004
10089654 20/11/2004

TIA,

Mark
Nov 13 '05 #1
3 1671
This example assumes that:
- ID, f_date, and Days are unbound text boxes on your form;
- you wish to add records to Table1, which fields named ID and f_date;
- the code is to run when you click a button named cmdAddRecords
- there are actually entries in all 3 boxes.

Private Sub cmdAddRecords_Click()
Dim rs As DAO.Recordset
Dim dt As Date
Dim dtEnd as Date

dtEnd = DateAdd("d", Me.Days - 1, Me.f_date)
Set rs = dbengine(0)(0).OpenRecordset("Table1", _
dbOpenDynaset, dbAppendOnly)
For dt = Me.f_date To dtEnd
rs.AddNew
rs!ID = Me.ID
rs!f_date = dt
rs.Update
Next
rs.Close
Set rs = Nothing
End Sub

That's completely untested, but should give you an example to work from.

--
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.

"Mark" <ma*********@ntlworld.com> wrote in message
news:Vh*************@newsfe5-gui.ntli.net...

What I am trying to achieve is for a user to enter a colleague
identification number into field [ID]. Then they are to add the first date
of holiday into field [f_date]. Finally they are to add the number of days
into an unbound text box [days]. Once a command is fired, I would like to
be able to add records into tbl_holidays. One for each date the person has
recorded.

e.g.
Input form:

ID f_date Days
10089654 16/11/2004 5

records to be added into table after closure of form:

ID booked_hols
10089654 16/11/2004
10089654 17/11/2004
10089654 18/11/2004
10089654 19/11/2004
10089654 20/11/2004

TIA,

Mark

Nov 13 '05 #2
Alan,
Thankyou very much. I had a slight problem when running the code with an
error message stating "Compile error: User-defined type not defined". I did
a quick check on the net and found that I could overcome this by checking
the microsoft DAO 3.51 object library from references.

Once this had been rectified, the code ran like a dream. Thanks again, much
appreciated.

Mark

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
This example assumes that:
- ID, f_date, and Days are unbound text boxes on your form;
- you wish to add records to Table1, which fields named ID and f_date;
- the code is to run when you click a button named cmdAddRecords
- there are actually entries in all 3 boxes.

Private Sub cmdAddRecords_Click()
Dim rs As DAO.Recordset
Dim dt As Date
Dim dtEnd as Date

dtEnd = DateAdd("d", Me.Days - 1, Me.f_date)
Set rs = dbengine(0)(0).OpenRecordset("Table1", _
dbOpenDynaset, dbAppendOnly)
For dt = Me.f_date To dtEnd
rs.AddNew
rs!ID = Me.ID
rs!f_date = dt
rs.Update
Next
rs.Close
Set rs = Nothing
End Sub

That's completely untested, but should give you an example to work from.

--
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.

"Mark" <ma*********@ntlworld.com> wrote in message
news:Vh*************@newsfe5-gui.ntli.net...

What I am trying to achieve is for a user to enter a colleague
identification number into field [ID]. Then they are to add the first
date of holiday into field [f_date]. Finally they are to add the number
of days into an unbound text box [days]. Once a command is fired, I would
like to be able to add records into tbl_holidays. One for each date the
person has recorded.

e.g.
Input form:

ID f_date Days
10089654 16/11/2004 5

records to be added into table after closure of form:

ID booked_hols
10089654 16/11/2004
10089654 17/11/2004
10089654 18/11/2004
10089654 19/11/2004
10089654 20/11/2004

TIA,

Mark


Nov 13 '05 #3
Well done.

If you did not have a DAO reference, you are probably running Access 2000 or
2002, because all other versions have the reference by default. In these
versions (and Access 2003), you should be using the DAO 3.6 library, not
3.51.

More info on references:
http://members.iinet.net.au/~allenbrowne/ser-38.html

--
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.

"Mark" <ma*********@ntlworld.com> wrote in message
news:sZ************@newsfe5-gui.ntli.net...
Alan,
Thankyou very much. I had a slight problem when running the code with
an error message stating "Compile error: User-defined type not defined". I
did a quick check on the net and found that I could overcome this by
checking the microsoft DAO 3.51 object library from references.

Once this had been rectified, the code ran like a dream. Thanks again,
much appreciated.

Mark

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
This example assumes that:
- ID, f_date, and Days are unbound text boxes on your form;
- you wish to add records to Table1, which fields named ID and f_date;
- the code is to run when you click a button named cmdAddRecords
- there are actually entries in all 3 boxes.

Private Sub cmdAddRecords_Click()
Dim rs As DAO.Recordset
Dim dt As Date
Dim dtEnd as Date

dtEnd = DateAdd("d", Me.Days - 1, Me.f_date)
Set rs = dbengine(0)(0).OpenRecordset("Table1", _
dbOpenDynaset, dbAppendOnly)
For dt = Me.f_date To dtEnd
rs.AddNew
rs!ID = Me.ID
rs!f_date = dt
rs.Update
Next
rs.Close
Set rs = Nothing
End Sub

That's completely untested, but should give you an example to work from.

"Mark" <ma*********@ntlworld.com> wrote in message
news:Vh*************@newsfe5-gui.ntli.net...

What I am trying to achieve is for a user to enter a colleague
identification number into field [ID]. Then they are to add the first
date of holiday into field [f_date]. Finally they are to add the number
of days into an unbound text box [days]. Once a command is fired, I
would like to be able to add records into tbl_holidays. One for each
date the person has recorded.

e.g.
Input form:

ID f_date Days
10089654 16/11/2004 5

records to be added into table after closure of form:

ID booked_hols
10089654 16/11/2004
10089654 17/11/2004
10089654 18/11/2004
10089654 19/11/2004
10089654 20/11/2004

Nov 13 '05 #4

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

Similar topics

11
by: Matt | last post by:
Hi everyone, still pretty new to MySQL. I was wondering if there is a way to automatically filter records based on a mysql userlogin name?? I have serveral databases that I want to combine in...
7
by: Bobby | last post by:
Please write suggestions on how to automatically increment time in a field (table or query). Example: Name | Time John Doe | 11:00 AM Jane Doe | 11:08 AM (8 minutes later) Jim Doe | 11:16...
5
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for...
6
by: HD | last post by:
Hello. For the following, I would appreciate if anyone could tell me: if it can be done, how it might done, and/or what search terms I could use to find the solution myself. I would like to...
5
by: deejayquai | last post by:
Hi I have a list of students undetaking various sports activities. Currently the students are listed in tblGroupMembers and I manually go into a form/subform and allocate each activity for each...
1
by: md7546 | last post by:
Hi, first time posting to this group, but I have followed advice and examples for several months, so thank you. I work for a small telecommunications company. I have a simple Orders database...
30
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and...
3
by: Iain | last post by:
How do I get a form to automatically refresh once (not continually using a timer). The scenario I have uses a parent table and a child table. (thanks to mmcarthy for indicating better termenology...
1
by: kkitto | last post by:
HI, I have 6 order book for issuing order numbers to suppliers. Each has 100 unique numbers in it which I need to create in a trackable database to track our outgoing payments against each order...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.