473,402 Members | 2,055 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,402 software developers and data experts.

Populating a Grid with dates

itchysf
31
Hi Every one,
I have a problem with a DB I'm building, I've got it all finisherd except the front form. What I'm trying to do is populate a grid of 9 rows by 14 colums with either arrival dates or departure dates, these dates are in a qryDailyBookings.
The 9 row are txtboxes names Room1 thu Room9 they are unbound.
The 14 colums are txtboxes named Date1 thru Date14 and have a controlsource of :
Expand|Select|Wrap|Line Numbers
  1. (code***)
  2. =DateAdd("d",0-14,[Startdate]), 
  3. (code/)
  4. [Startdate] being an unbound txtbox with an popup calander for users to select a date from. 
  5. The grid is made up (about half so far) with onbound txtboxes. What I have done so far is put the Iff expression:
  6. (code***)
  7.  (=IIf([Room1]=[RoomNumber] And [Date2]=[ArrivalDate],[ArrivalDate],IIf([Room1]=[RoomNumber] And [Date2]=[DepartureDate],[DepartureDate],Null))) 
  8. (code/)
  9. in the controlsource of these txtboxes, but as you can see this is not very good, as you have to click through all records to get a result.
  10. What I'm asking is there anyway to use VBA to loop through the records of ArrivalDates and DepartureDates to populate the grid all at once when a date is picked with out clicking thru the records one at a time.
  11. I've also got VBA loop:
  12. (code***)
  13.  Private Sub Form_Current()
  14. On Error Resume Next
  15. For Each c In Me.Controls
  16.  If InStr(1, c.Name, "Text") <> 0 Then
  17.  If c.Value = DepartureDate.Value Then
  18.  c.ForeColor = vbRed
  19.  Else
  20.  c.ForeColor = vbBlack
  21.  End If
  22.  End If
  23.  Next
  24. On Error GoTo 0
  25. End Sub
  26. (code/)
which works to change the entered departure date to red so you can tell them apart.
Hope you can understand this and can help.
Thanks itchysf
Aug 31 '08
59 6292
itchysf
31
Hi itchysf,
No heartaches, just a challenge. I think the attached is pretty close if not the final. I accomplished it using a minimal amount of code. I did some light testing, but you need to test thoroughly in your environment. Let me know.

pDog
THANKS, you are a great mate, after testing for two days, it works great, cann't find anything wrong, again thanks a lot.
Oct 29 '08 #51
itchysf
31
Looks like I spoke too soon, what is happening is I have put another guest in arriving 3/11/2008 and departing on the 5/11/2008. When you select a date (19/10) so that the guest who booked in on the 20/10/2008 are shown on the grid, it works fine in all aspects. Then when you reselect a date (2/11) so the guest who arrives on the 3/11 is to be shown, all works well but the guest for the 20/10 do not get deleted from the grid and the rooms for those guests are shown as occupied, is there someway that the grid can be cleared of guests each time a new date is selected from the calander so only the guests for the chosen week are shown.
Thanks itchysf.
Oct 30 '08 #52
puppydogbuddy
1,923 Expert 1GB
Looks like I spoke too soon, what is happening is I have put another guest in arriving 3/11/2008 and departing on the 5/11/2008. When you select a date (19/10) so that the guest who booked in on the 20/10/2008 are shown on the grid, it works fine in all aspects. Then when you reselect a date (2/11) so the guest who arrives on the 3/11 is to be shown, all works well but the guest for the 20/10 do not get deleted from the grid and the rooms for those guests are shown as occupied, is there someway that the grid can be cleared of guests each time a new date is selected from the calander so only the guests for the chosen week are shown.
Thanks itchysf.
Hi itchsf,

That is a constraint that you should put in the criteria row of the query (qryDailyBookings) that is the source for the grid.
Oct 30 '08 #53
puppydogbuddy
1,923 Expert 1GB
Itchysf,
If you don't know how to do that, hear is the sql of qryDailyBookings, modified to compute the number of days between arrival and departure.
Expand|Select|Wrap|Line Numbers
  1. SELECT tblReservation.RoomNumber, tblReservation.ArrivalDate, tblReservation.DepartureDate, tblReservation.CustomerID, DateDiff("d",DateValue([ArrivalDate]),DateValue([DepartureDate])) AS NumDays
  2. FROM tblReservation
  3. WHERE (((tblReservation.ArrivalDate)>=DateDiff("d",Date()-Month(Date()),Date())) AND ((tblReservation.DepartureDate)>=DateDiff("d",Date()-Month(Date()),Date())))
  4. ORDER BY tblReservation.RoomNumber;
You already have a constraint on the arrival and departure dates to display only arrivals in the current month. I added a column to calculate the number of days between Arrival and Departure that would be used for billing purposes.

Maybe you can add an additional constraint in the criteria row that the NumDays must be : nz([NumDays]) <= 8 because the grid basically displays only 8 days of activity from the starting date.

If you need further help, let me know.
Oct 30 '08 #54
itchysf
31
Hi itchsf,

That is a constraint that you should put in the criteria row of the query (qryDailyBookings) that is the source for the grid.


Dumb me, yes I do know how to do that, I had a lot on yesterday and not thinking, I was trying to work it out through your code, which I must admit I don't understand much off, (more schooling needed), also thanks for the extra coding.

I am going to expand the grid to cover 2 weeks so the nz([NumDays])<=8 will be changed to <=15.
Thanks again puppydogbuddy.
Oct 31 '08 #55
puppydogbuddy
1,923 Expert 1GB
You are welcome. Glad it works to your satisfaction. I don't normally spend this much pro bono time on one project, but learned a lot by doing it....so it was a win win situation.
Oct 31 '08 #56
itchysf
31
Hi All,
I am still having problems with the Grid population on my Db, I have extended the number of days covered to 14 and have the days being filled in for the whole form. The problem is that all rooms are not showing up for the whole 14 days, If 17/11/2008 is picked from the calendar all booked rooms 1,6,3,9,8,4,& 5 show as required, but not rm 7, pick 18/11 and only rm 9 & 5 show, 19/11 only rm 3,9,4,& 5 show, 20/11 only rm 1,3,9,4,& 5 show, 21/11 only rm 1,6,3,9,8,4, & 5 show. Room 2 has a guest booked in on the 1/12 this does not show up on the grid until you pick 29/11. Room 7 has a guest booked in on the 29/11 and this does not show up until you pick the 29/11. Any ideas why this is happening.

Another problem i am having is entering a new guests details. On entering thier details in the Reservation form a going to the next form(button Tariff) and picking there Customer ID number from the drop down list you get a message "Field cannot be updated", on opening the help file it says" you tried to change the value of a control whose locked value is set to yes" this not so, all locked propeerties are set to "No". I am the only one using the DB. This happens three times and then the form can be used, the text boxes it happens on are CustomerID, Name and Reservation ID.
Again any ideas on why this is happening, any help will be greatly appreciated.
Itchysf
Nov 20 '08 #57
puppydogbuddy
1,923 Expert 1GB
Hi All,
I am still having problems with the Grid population on my Db, I have extended the number of days covered to 14 and have the days being filled in for the whole form. The problem is that all rooms are not showing up for the whole 14 days, If 17/11/2008 is picked from the calendar all booked rooms 1,6,3,9,8,4,& 5 show as required, but not rm 7, pick 18/11 and only rm 9 & 5 show, 19/11 only rm 3,9,4,& 5 show, 20/11 only rm 1,3,9,4,& 5 show, 21/11 only rm 1,6,3,9,8,4, & 5 show. Room 2 has a guest booked in on the 1/12 this does not show up on the grid until you pick 29/11. Room 7 has a guest booked in on the 29/11 and this does not show up until you pick the 29/11. Any ideas why this is happening.

Another problem i am having is entering a new guests details. On entering thier details in the Reservation form a going to the next form(button Tariff) and picking there Customer ID number from the drop down list you get a message "Field cannot be updated", on opening the help file it says" you tried to change the value of a control whose locked value is set to yes" this not so, all locked propeerties are set to "No". I am the only one using the DB. This happens three times and then the form can be used, the text boxes it happens on are CustomerID, Name and Reservation ID.
Again any ideas on why this is happening, any help will be greatly appreciated.
Itchysf
I don't have any idea, but the place to start looking is qryDailyBookings which is the data source for the grid. Compare the query results with the grid display. Do they match or are they different? If they match, then the problem most likely is the query, not the grid. Have you modified the query or Added new constraints recently?
Nov 20 '08 #58
itchysf
31
I don't have any idea, but the place to start looking is qryDailyBookings which is the data source for the grid. Compare the query results with the grid display. Do they match or are they different? If they match, then the problem most likely is the query, not the grid. Have you modified the query or Added new constraints recently?
qryDailyBookings has not been changed in any way, the qry results match the grid display on the dates that it are displayed, I cann't work out why when sume dates are picked from the calendar all rooms show up correctly and when other dates are picked only sume room show up. The only thing I have done is add a bit of code before your code runs to populate the grid, the code clears the form of prevoiusly populated grids, the code is:
Expand|Select|Wrap|Line Numbers
  1.          On Error Resume Next
  2.          For Each c In Me.Controls
  3.        If InStr(1, c.Name, "Day") <> 0 Then
  4.             c.Value = Vaccant
  5.             c.BackColor = vbWhite
  6.      End If
  7.  
  8. Next
  9. On Error GoTo 0
  10.  
Nov 21 '08 #59
puppydogbuddy
1,923 Expert 1GB
qryDailyBookings has not been changed in any way, the qry results match the grid display on the dates that it are displayed, I cann't work out why when sume dates are picked from the calendar all rooms show up correctly and when other dates are picked only sume room show up. The only thing I have done is add a bit of code before your code runs to populate the grid, the code clears the form of prevoiusly populated grids, the code is:
Expand|Select|Wrap|Line Numbers
  1.          On Error Resume Next
  2.          For Each c In Me.Controls
  3.        If InStr(1, c.Name, "Day") <> 0 Then
  4.             c.Value = Vaccant
  5.             c.BackColor = vbWhite
  6.      End If
  7.  
  8. Next
  9. On Error GoTo 0
  10.  
Your new code appears to be the cause of the problem. It conflicts with part of the code I put in (excerpted below). Instead of adding your code, you should have added one line to the code I gave you (shown below).

Expand|Select|Wrap|Line Numbers
  1. Loop
  2.  
  3.   'make a final loop around the grid to pick up and identify all vacancies, where the calendar
  4.     ' date is prior to the arrival and where the calendar date is after the departure date
  5.     On Error Resume Next
  6.        For Each ctl In Me.Controls
  7.            If InStr(1, ctl.Name, "Day") <> 0 Then
  8.               If IsNull(ctl.Value) Then
  9.                  ctl.Value = "Vacant"
  10.                  ctl.BackColor = vbWhite       '<<<<<<<<<<<<<<add this line
  11.               End If
  12.            End If
  13.        Next
  14.     On Error GoTo 0
  15.  
  16. Else
  17.     Exit Sub
  18. End If
Nov 21 '08 #60

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Peter Bailey | last post by:
I have a vba string taht dynamically creates the query which has two dates in it that it grabs off an open form as a string from the textbox. What I generate in vba is: SELECT DOSMBK.Date,...
3
by: Serious_Practitioner | last post by:
Good day, and thank you in advance for any assistance you can provide. I have a table in an Access 2000 .mdb file, and I've run into something odd and insolvable, at least for me. The database is...
6
by: P K | last post by:
I have a listbox which I am populating on the client (it contains a list of dates selected from calender). The listbox is a server control. When I get to the server after postback by selecting an...
0
by: hlam | last post by:
Help - Calculating the total of a column in a data grid -- when data grid is part of Master-Detail set-up I have setup a Master-Detail form using Visual Studio.Net. A ListBox is the (Master)...
2
by: Unforgiven | last post by:
Hello All, I have the following query... SELECT Demographics.Full_Name, Demographics.Year_of_birth, Status.Status_OK, SUM(2004 - Demographics.Year_of_birth) AS Age FROM Demographics INNER...
1
by: Dave Hutchings | last post by:
Hi, My problem is this, I have a search screen which creates a query that performs a search on a large database. The results of this search could, if the user requires, return many many rows...
1
by: el_83 | last post by:
Hi I was wondering if someone could help me. I have not used activewidgets before and i wanted to know if it is possible to use it to populate a grid that exsists on another's webpage. That is,...
0
by: Eric B. | last post by:
I am populating a DataGrid with many rows. As it is populating I see the scrollbar flying but no rows pop up until it is finished. Is there a way to make each row draw as soon as it is...
2
by: Mike P | last post by:
I need to create a grid which along the y axis has a user name and along the x axis has a date. Somehow I need to populate the x axis with 6 months worth of dates from the current date, and then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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,...
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.