Results 1 to 6 of 6
  1. #1
    NickWren is offline Advanced Beginner
    Windows XP Access 2013
    Join Date
    Dec 2015
    Location
    Connecticut
    Posts
    70

    Angry Setting a Default Value for a subform from a main form

    On the main form I have a field called "FacilityAbbreviation", I want to use this field to set the default values on a subform.



    Code:
    Private Sub Form_Load()
    [Forms]![frmAddFacilityPatients]![subformtblNewFacilityPatient].[Form]![FacilityAbbreviation].DefaultValue = Me.FacilityAbbreviation.Value
    Me.Text15 = Me.FacilityAbbreviation.Value
    End Sub

    This should work; I get a #NAME? in the FacilityAbbreviation field in the subform; and I get the Facility Abbreviation in Text15. how come its being put into the textbox but not the subform correctly? Is it because of the event?

    I am going to try and switch it up right now and try and pull the value from the subform instead of the subform trying to have the data in-put;
    I tried this but still same results... maybe I need to try Me.FacilityAbbreviation.text? or making that into a string before putting it into the subform.

  2. #2
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    Have you tried removing .DefaultValue? And there is no need to use .Value, which is the default. More on this at http://www.baldyweb.com/ValueText.htm

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You could try putting the new default value in quotes and/or using the bang (!) instead of a period to refer to the form control:

    [Forms]![frmAddFacilityPatients]![subformtblNewFacilityPatient].[Form]![FacilityAbbreviation].DefaultValue = "'" & Me!FacilityAbbreviation.Value & "'"

  4. #4
    NickWren is offline Advanced Beginner
    Windows XP Access 2013
    Join Date
    Dec 2015
    Location
    Connecticut
    Posts
    70
    Alright John_G I will give your suggestion a try and let you know how it works out. But jwhite, when I tried to enter it in as a value; it starts a new record for me (so if you click on the button by accident; now you have a new record and an auto number started, therefore possible messing up the sequence).

  5. #5
    NickWren is offline Advanced Beginner
    Windows XP Access 2013
    Join Date
    Dec 2015
    Location
    Connecticut
    Posts
    70
    THANK YOU SO MUCH JOHN_G THAT WORKED PERFECTLY!!!! I why would that even effect if the value went into the default field? is it because it didnt see it as a string?

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I was wondering about that as well. The only thing I can think of is that somehow Access was confused by the use of the period instead of the bang. I have found that while the period and bang are usually interchangeable, sometimes they are not, and maybe this is one of those times. From what the experts here have said, this can be true if your control name and the name of the field it is bound to are the same.

    But you have the problem solved, and that's really what matters. Glad I could help.

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

Similar Threads

  1. Replies: 1
    Last Post: 05-08-2015, 08:36 AM
  2. Setting default value on a form from a Query
    By rjgriffin46 in forum Access
    Replies: 18
    Last Post: 12-12-2014, 02:37 PM
  3. Setting default value to zero in form box?
    By dekhelia in forum Forms
    Replies: 6
    Last Post: 10-17-2013, 08:53 AM
  4. Replies: 8
    Last Post: 03-03-2013, 02:53 PM
  5. Replies: 6
    Last Post: 10-20-2012, 04:45 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