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

Another update problem?

Ray
Any help? I have two tables. TABLE 1 one which shows all the days of
the year with

[BookingID] (Number)
[Revdate](date) Each day of the year
[Booked](Yes/No)

TABLE 2 with reservation details with

[BookingID] (Autonumber)
[DateIn](date)
[NoOfNights] (number)

I believe that I'm sort of on the right track. What I would like to be
able to do is to update TABLE 1 with the information from TABLE 2 i.e.
a BookingNo and [Booked] (Yes/No). TABLE 2 shows the night the guest
arrives and number of nights they stay. I would like to show in TABLE
1 that those dates are now booked.

TABLE 2

20/2/2004 1 night BookingID = 1

24/2/2004 – 25/2/2004 2 nights BookingID = 2 etc
TABLE 1
Booking ID RevDate Booked

0 19/2/2004 No
1 20/2/2004 Yes
0 21/2/2004 No
0 22/2/2004 No
0 23/2/2004 No
2 24/2/2004 Yes
2 25/2/2004 Yes
0 26/2/2004 No

I imagine that I use something like an update VB but I'm fairly lost
at this stage. The [NoofNights] needs to update the dates. Have I made
myself sufficiently clear?

TIA - Ray
Nov 12 '05 #1
3 1408
On 14 Feb 2004 13:32:45 -0800, Ray wrote:
Any help? I have two tables. TABLE 1 one which shows all the days of
the year with

[BookingID] (Number)
[Revdate](date) Each day of the year
[Booked](Yes/No)

TABLE 2 with reservation details with

[BookingID] (Autonumber)
[DateIn](date)
[NoOfNights] (number)

I believe that I'm sort of on the right track. What I would like to be
able to do is to update TABLE 1 with the information from TABLE 2 i.e.
a BookingNo and [Booked] (Yes/No). TABLE 2 shows the night the guest
arrives and number of nights they stay. I would like to show in TABLE
1 that those dates are now booked.

TABLE 2

20/2/2004 1 night BookingID = 1

24/2/2004 – 25/2/2004 2 nights BookingID = 2 etc
TABLE 1
Booking ID RevDate Booked

0 19/2/2004 No
1 20/2/2004 Yes
0 21/2/2004 No
0 22/2/2004 No
0 23/2/2004 No
2 24/2/2004 Yes
2 25/2/2004 Yes
0 26/2/2004 No

I imagine that I use something like an update VB but I'm fairly lost
at this stage. The [NoofNights] needs to update the dates. Have I made
myself sufficiently clear?

TIA - Ray


After writing this, i realized that you have a date range in the example of
the Table2 structure. Waste of time if you are storing the number of nights
there as well. The example below requires only one date to be in that
field. Becomes more complicated with two. I didn't test this or anything,
so no warranties implied.

Function AppendDatesBooked() as Boolean
On Error Goto Stoprun
AppendDatesBooked = False

Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim db As Database
Dim BookID As Long
Dim NumNights As Long
Dim StrtDate as Date
Dim cntr As Long

Set db = CurrentDb
Set rst1 = db.OpenRecordset("Table1", dbOpenDynaset)
Set rst2 = db.OpenRecordset("Table2", dbOpenSnapShot)

With rset2
Do Until .EOF = True
BookID = !BookingID
NumNights = !NoOfNightd
StrtDate = !DateIn
Do Until cntr = NumNights
rset1.AddNew
rset1!BookingID = BookID
rset1!RevDate = DateAdd("d", cntr, StrtDate)
rset1.Booked = True
rset1.Update
cntr = cntr +1
Loop
.MoveNext
Loop

AppendDatesBooked = True

Exit_Here:
Exit Function

stoprun:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Here

End Function
--
Mike Storr
veraccess.com
Nov 12 '05 #2
Ray
Mike Storr <st******@sympatico.ca> wrote in message news:<4z****************************@40tude.net>.. .
On 14 Feb 2004 13:32:45 -0800, Ray wrote:
Any help? I have two tables. TABLE 1 one which shows all the days of
the year with

[BookingID] (Number)
[Revdate](date) Each day of the year
[Booked](Yes/No)

TABLE 2 with reservation details with

[BookingID] (Autonumber)
[DateIn](date)
[NoOfNights] (number)

I believe that I'm sort of on the right track. What I would like to be
able to do is to update TABLE 1 with the information from TABLE 2 i.e.
a BookingNo and [Booked] (Yes/No). TABLE 2 shows the night the guest
arrives and number of nights they stay. I would like to show in TABLE
1 that those dates are now booked.

TABLE 2

20/2/2004 1 night BookingID = 1

24/2/2004 ? 25/2/2004 2 nights BookingID = 2 etc
TABLE 1
Booking ID RevDate Booked

0 19/2/2004 No
1 20/2/2004 Yes
0 21/2/2004 No
0 22/2/2004 No
0 23/2/2004 No
2 24/2/2004 Yes
2 25/2/2004 Yes
0 26/2/2004 No

I imagine that I use something like an update VB but I'm fairly lost
at this stage. The [NoofNights] needs to update the dates. Have I made
myself sufficiently clear?

TIA - Ray


After writing this, i realized that you have a date range in the example of
the Table2 structure. Waste of time if you are storing the number of nights
there as well. The example below requires only one date to be in that
field. Becomes more complicated with two. I didn't test this or anything,
so no warranties implied.

Function AppendDatesBooked() as Boolean
On Error Goto Stoprun
AppendDatesBooked = False

Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim db As Database
Dim BookID As Long
Dim NumNights As Long
Dim StrtDate as Date
Dim cntr As Long

Set db = CurrentDb
Set rst1 = db.OpenRecordset("Table1", dbOpenDynaset)
Set rst2 = db.OpenRecordset("Table2", dbOpenSnapShot)

With rset2
Do Until .EOF = True
BookID = !BookingID
NumNights = !NoOfNightd
StrtDate = !DateIn
Do Until cntr = NumNights
rset1.AddNew
rset1!BookingID = BookID
rset1!RevDate = DateAdd("d", cntr, StrtDate)
rset1.Booked = True
rset1.Update
cntr = cntr +1
Loop
.MoveNext
Loop

AppendDatesBooked = True

Exit_Here:
Exit Function

stoprun:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Here

End Function


Thanks Mike for your reply which works! However, instead of appending
the date to the table I would like to have a table which lists evry
date for the year and then to update the [Booked] to yes or no. That
way I can search for a booked room and a non-booked room. Can the
above code be modified to do this for the days booked. The booking
dates come from a form based on Table1.

have I made myself clear? TIA - Ray
Nov 12 '05 #3
On 15 Feb 2004 10:21:35 -0800, Ray wrote:
Thanks Mike for your reply which works! However, instead of appending
the date to the table I would like to have a table which lists evry
date for the year and then to update the [Booked] to yes or no. That
way I can search for a booked room and a non-booked room. Can the
above code be modified to do this for the days booked. The booking
dates come from a form based on Table1.

have I made myself clear? TIA - Ray


If I understand correctly, you want a table, pre-populated with dates, then
to update them as necessary? This is rather inefficient. Besides, how many
of each day of the year do you add? One for each room right? That means
you'd have one record in the table for each room on each day of the year -
wheter it was being used or not. You'd be better served with a different
table structure. I think you should rethink you're schema before
continuing.
This isn't homework is it? Seems to be a lot of room booking questions
lately.

--
Mike Storr
veraccess.com
Nov 12 '05 #4

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

Similar topics

2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
3
by: David W. Fenton | last post by:
A very old app of mine that's been in production use, and largely unchanged since about 1998 has started recently throwing error 3188 (can't update, locked by another session on this machine) when...
1
by: Mark Reed | last post by:
Hi All, I'm having a problem with the following code. I've read quite a lot of old posts regarding the issue but none seem to affer a solution. The scenario is. I have a bound form which...
0
by: Phillip Vong | last post by:
Doing this in VS2005. ASPX in VB code. This image details my problem. http://ebay.philvong.com/help.jpg I have a simple FormView1 bound to a SQLDataSource1. In edit mode, Label1 is bound to a...
13
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever...
3
by: wvmbark | last post by:
First time poster... I just found this forum and it appears there's plenty of people here that could make short work of problem that's been driving me absolutely bonkers for months. Every day we...
1
by: corsibu | last post by:
hello , i just wanted to ask if there's anyone who could help me do the following thing : i have an empty temporary table, this table will have a row filled with data grabbed by a querry at this...
2
by: tomash | last post by:
Hi! I ve got two tables in Access 2007. I want to update a field of DataTable from another table, DataSumTable when two of their fields equals. ( the fields : Name and Period) I tried this...
9
by: Peter Webb | last post by:
I want to animate one object moving in front of another. I cannot re-render the background as the object moves, as it would be extremely time consuming. This is what I would like to do. I draw...
3
by: robin1983 | last post by:
HI all, how are you ? i need help from you people. This time my problem is that i m running a query inside another query. But, the result that i got is something not exactly what i want. and one...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.