Results 1 to 4 of 4
  1. #1
    jpalk is offline Novice
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    4

    Selecting Dates

    Hello,

    I am a pretty new user to Access through work. I have a project I'm working on, and am not sure how to make it work. I assume a query will be necessary to accomplish this, so I've posted here, but if I should re-post elsewhere just let me know!

    The scenario is this:

    Our business is a resort. I would like to be able to input a guest's arrival date and the number of nights that they stay, and have the actual date of each day they will be at the resort returned in a selectable list.

    So, for example, if a guest arrives May 1 for 7 days, the return will list May 1, May 2, May 3, May 4, May 5, May 6, & May 7.

    Here's the catch--I need this list to return in a list box on a form or each in separate text boxes so we can select dates from those returned dates. If a guest wants to sign up for a particular activity at the resort on 3 of the 7 dates, but they are not "in a row," I want to be able to select the 3 days they've elected to join the activity so when we print out a report of all the guests requesting an activity on a certain date, they will do so.



    Hopefully I have explained this clearly enough; I've tried to keep it as simple as possible. If anyone has any idea what I'm talking about & how I might do it, I'd really appreciate the help. I've done so much research in the Help sections & online to try & figure it out on my own, with no luck.

    Thank you thank you!
    Jess

  2. #2
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    To return the result in a List Box, use the following Code:

    Assumptions:
    You are getting the number of days a guest is staying from a Text Box named "StayLength"
    You are getting the guest's arrival date from a Text Box named "ArrivalDate"
    Your List Box is called "AvailableDates"

    Code:
      ' Empty out our List Box
      Me!AvailableDates.RowSource = ""
    
      ' Run this loop once for each day the guest is staying
      For i = 0 To (Me!StayLength - 1)
        If i = 0 Then
          ' If this is the first date, just set the RowSource of your List Box to the guest's Arrival Date
          Me!AvailableDates.RowSource = Me!ArrivalDate
        Else
          ' Otherwise, use our counter (i) to add to our Arrival Date and use that instead
          Me!AvailableDates.RowSource = Me!AvailableDates.RowSource & ";" & DateAdd("d", i, Me!ArrivalDate)
        End If
      Next
    Try putting that in the StayLength's After Update Event and see how it works for ya.

    EDIT: Added bold to the names of the various Form Objects that may need to be changed.
    Last edited by Rawb; 05-21-2010 at 06:10 AM.

  3. #3
    jpalk is offline Novice
    Windows XP Access 2003
    Join Date
    May 2010
    Posts
    4

    Thank you--any changes?

    Hi,

    Thanks so much for your quick response, I appreciate it.

    Because I'm so new, & have no experience with VBA or code of any kind, before I plug this in can I just copy & paste it in, or do I need to replace anything with my own data?

    So excited to give this a try, thanks again for your help!

    Jess

  4. #4
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Quote Originally Posted by jpalk View Post
    Hi,

    Thanks so much for your quick response, I appreciate it.

    Because I'm so new, & have no experience with VBA or code of any kind, before I plug this in can I just copy & paste it in, or do I need to replace anything with my own data?

    So excited to give this a try, thanks again for your help!

    Jess
    The VBA Code posted above is pretty much ready to go. All you should have to do is cut & paste it into the "After Update" Event of whatever Form Object you fill out last.

    Make sure you change the bolded sections to whatever you're using as the names of your Form Objects though.

    P.S.
    The bold text wasn't there until just now >.>

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Selecting between two dates
    By nicorvp in forum Queries
    Replies: 5
    Last Post: 05-04-2010, 08:17 AM
  2. Selecting next set of control No's
    By newtoAccess in forum Queries
    Replies: 0
    Last Post: 02-28-2010, 10:28 AM
  3. Selecting random with exclutions
    By owutne in forum Queries
    Replies: 1
    Last Post: 02-03-2010, 09:33 PM
  4. Selecting Just One Name Type
    By susan in forum Queries
    Replies: 1
    Last Post: 12-03-2009, 12:08 PM
  5. Selecting text - ComboBox
    By Numbat in forum Programming
    Replies: 2
    Last Post: 06-05-2006, 05:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums