Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2022
    Posts
    8

    How do i get a date to repeat in a form connected to a table/query

    Not sure if I asked this question or not, and i am a basic user of Access
    i have set up a database and am using a one to many form for data input..ie 1 specific venue will have up to 30 leaflets entered against it for one entry. each Leaflet has a date put against it, which is very time consuming. After entering the first leaflet date, I would like the subsequent leaflet dates entered to automatically put the same date in as the first date entered. I'm not sure how to do this....any ideas. See Picture of entry form on attached word documentdatabase picture.zip

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    This is how I have done it, and actually using it today, on several controls.
    I have a checkbox to indicate whether I wish to copy previous values or not.
    Code:
    Private Sub Ship_ID_AfterUpdate()
        If Me.chkCopy Then
            Me![Ship_ID].DefaultValue = """" & Me![Ship_ID].Value & """"
        Else
            Me![Ship_ID].DefaultValue = 0
        End If
    
    
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Join Date
    Jan 2022
    Posts
    8
    Many thanks, as i said I,m a basic user.....whereabouts do i type this please.

    regards

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by whiting523@sky.com View Post
    Many thanks, as i said I,m a basic user.....whereabouts do i type this please.

    regards
    In the AfterUpdate event of the control, as I have shown?
    You will need to change the name of the control to whatever you are using though.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    Join Date
    Jan 2022
    Posts
    8
    Copied this word for word, apart from Ship ID, which I replaced with DateDelivered....did not work
    Did not seem to like 'chkCopy'....comes up with Compile Error and Syntax Error
    also do i need to put the brackets around 'DateDelivered' and do i need to add '_ID'

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    No,
    You cannot copy word for word. it is not a recipe, just a guide as to how I did it.
    Think of it more as how to check the oil in your car. the dipstick is in a different location.


    The main part you want is DefaultValue. I did say that the chkCopy allows me to decide whether I want to copy the last value or not. More flexible, but if you want to use that feature, then you need a checkbox called that?

    TBH not sure about Dates, as though I have Dates in that DB and do copy last value, it is the ID of the Dates record I am copying, not the date itself. Dates usually need to be enclosed by #

    So just try with your controlname with the code below
    [code]
    Me![Ship_ID].DefaultValue = """" & Me![Ship_ID].Value & """"
    [code]

    You appear to be getting more response on your crosspost in AWF, so why are you continuing here?

    Here is how Allen Browne approcahed it? http://allenbrowne.com/ser-24.html
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Seems from the crosspost all you need, is as I supplied?
    From AWF
    Code:
    Private Sub DateDelivered_AfterUpdate()
      Const cQuote = """"  'Thats two quotes
      Me.DateDelivered.DefaultValue = cQuote & Me.DateDelivered.Value & cQuote
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    Join Date
    Apr 2017
    Posts
    1,681
    I'd advice a design, where:
    1. You have a single form based on your venue? table (main form) - i.e. you select a venue there. In same form, you have an unbound control, where user can enter/select date;
    2. You have a continuous subform based on table where all venue leaflets are registered (the table will have at least fields for venue leaflet id, venue id and for date) in main form (the one where venue is activated);
    3. The subform must be linked to venue form by venue id, and by date (subform date is linked to date selected in unbound control of main form).

    When designed properly, any new entry in subform will be linked to active venue, and will have date in main form's unbound control entered into venue leaflets table date control automatically. No additional code is needed!

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

Similar Threads

  1. Replies: 1
    Last Post: 11-06-2019, 05:30 PM
  2. Replies: 3
    Last Post: 03-08-2019, 02:41 PM
  3. Replies: 9
    Last Post: 04-06-2018, 11:02 AM
  4. Replies: 30
    Last Post: 08-15-2012, 02:25 PM
  5. Two textboxes connected to the same table
    By ma09fraga in forum Forms
    Replies: 6
    Last Post: 06-11-2009, 12: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