Results 1 to 9 of 9
  1. #1
    jonanem is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2017
    Location
    Devon
    Posts
    3

    using default =date() when a form opens

    Hi,
    I have an enquiry form frmEnquiry with two buttons, one to open frmFascia and the other to open frmSiteboard (I am trying to create a database for my son who is a sign maker). I can get the buttons to open each form at a new record and the current enquiryID if I use the datepicker on frm Enquiry, but if I set the EnquiryDate to default =date(), then the enquiry ID does not get created on frmEnquiry and so is not sent to frmFascia or frmSiteboard wwhen they are opened.
    Is there any code that I can use so that EnquiryDate is entered automatically (using the default property) which produces the next EnquiryID which can then be passed to frmFascia or frmSiteboard? At the moment when I close these forms the message comes up that the record can't be saved because there is no corresponding entry in tblEnquiry.
    Any help would be very much appreciated,
    thanking you in advance,


    jonanem

    Database6.accdb

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,923
    Do a Compact and Repair of the db and then zip it up. I can't read what you have uploaded, sorry.

  3. #3
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    11,085
    if I set the EnquiryDate to default =date()
    Where, the table? When creating a new record, any default values have not been committed until the record is saved, so you cannot search on something, or use it as criteria, when it doesn't actually exist. If that is your issue, you'll need to better explain what it is you're trying to do - avoiding ambiguity as much as possible.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    51,338
    DefaultValue property will not provoke creation of autonumber ID. Have to do data entry in some field, that means typing (textbox, combobox, checkbox, radio button) or selecting from a combobox/listbox list.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    11,085
    DefaultValue property will not provoke creation of autonumber ID. Have to do data entry in some field, that means typing (textbox, combobox, checkbox, radio button) or selecting from a combobox/listbox list.
    While doing so will generate a default value in any field that uses one, it doesn't actually exist until, as I noted, the record is saved. If you edit a field and generate the number, that ID number cannot be queried as it hasn't been saved yet. You have to do something that causes the record to be saved before it will show up in any query. I presume that also means that the default value(s) cannot be used in any other fashion as well, such as linking between main and sub forms.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    51,338
    Didn't intend to imply otherwise, just offering more info. Also, makes me question why the dependent forms are being opened as individual forms and not designing a form/subform arrangement.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    jonanem is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2017
    Location
    Devon
    Posts
    3
    Wow, I've never used this (or any other) forum before and I must say thank you to all who took the trouble to respond and so quickly.
    In short, then, there is no way that a record can be saved and no code that can be written to save a record if the only entry is the default date.
    I did try creating one table (tblEnquiry) with two fields: EnquiryID and EnquiryDate a

  8. #8
    jonanem is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2017
    Location
    Devon
    Posts
    3
    Wow, I've never used this forum before and I must say thank you to all who took the trouble to respond and so quickly. In short, there is no way that a record can be saved if the only entry is the default date.
    I did try by creating a single table tblEnquiry (fields: EnquiryID and EnquiryDate) and frmEnquiry (txtEnquiryDate) . Using the date picker on the form, date record saved; using 'default' date, date record not saved. What a pity there is no code to do this, but thanks all once again,
    jonanem

  9. #9
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    11,085
    Since the default would be the current date anyway, I have to wonder why you don't just create the record using the Date function. This is probably what you wanted all along, but I think we focused on answering questions around your chosen method rather than providing an alternate solution. At least I did. If I'm right, you don't need any code as an alternative to using a default value at the table level - you need an append query (if there is no record yet). That will trigger the save of the EnquiryID if I understand the design. If there is another form (such as a subform) that requires a value in another field to link on besides the date or EnquiryID, your update query should probably handle that as well.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2017, 07:30 PM
  2. Replies: 15
    Last Post: 07-24-2014, 09:45 AM
  3. Replies: 2
    Last Post: 02-20-2014, 09:53 AM
  4. Default Date In A Form
    By scubagal in forum Forms
    Replies: 7
    Last Post: 03-08-2012, 11:36 AM
  5. Default Min & Max Date Values in Form
    By alsoto in forum Forms
    Replies: 3
    Last Post: 10-03-2011, 10:54 AM

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