Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167

    Change DefaulValue on a second field

    Hello my friends,




    I'm trying to find a way on how can i change the default value of an unbound field.


    Example:
    I have one form which includs two unbound fields (the Field1 & Field2).


    What i want is:


    Each time when i change the value on Field1 (Control Field) i want to change the DefaultValue on field [Field2]. Although I have found a way to do this with a simple line of code (on the "After Update" event of the first field - attached following) (Me.Field2.DefaultValue = Me.Field1.Value) but it doesn't work. When I say "doesn't work" i mean that, when you close the form and then re-open it, the default value of [Field2] remain as before..!!


    Your lights and any idea for help appreciated.

    Thanks in advanced
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Changing the DefaultValue property is changing form design. This change is not permanent unless you save the form design when closing the form. Otherwise, next time form opens it will use the DefaultValue originally set in the form design.
    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.

  3. #3
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Hi June7 and thanks,

    But, could you please explain me on how can i save the form design? I didn;t understand... ! I must change something on vba code?
    Thanks again

  4. #4
    R. Hicks is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2016
    Location
    Birmingham, Alabama USA
    Posts
    3
    Maybe you can explain why you need this ...
    Sounds like to me that you have one field in your table dependent of another field in the same table.
    This usually not a good thing in the design of a database.
    This is why I'm asking what you are trying to do .. and why you are doing it.

    R.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Maybe:

    Private Sub Form_Close()
    DoCmd.RunCommand acCmdSave
    End Sub
    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.

  6. #6
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    But to save changes to design, form must be opened in design mode first. So I think you would have to:
    - save this new default value to public variable
    - close your form
    - open it in design mode
    Code:
    DoCmd.OpenForm "myForm", acDesign, , , , acHidden
    - change default value of textbox to saved variable
    Code:
    Forms("myForm")!myTextField.DefaultValue = mySavedVariable
    - save form design and close it
    Code:
    DoCmd.Close acForm, "myForm", acSaveYes

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The usual solution is VBA that looks up the maximum value of a field or a value from the most recent record and sets the DefaultValue when form opens.
    Last edited by June7; 01-11-2016 at 01:42 PM.
    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.

  8. #8
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Guys thanks a lot for your information.

    The problem has been solved using your details. Thanks again

  9. #9
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Hello my friends again. I'm back again because of serious issue..!!


    As I said the problem has been solved but,......what can we do after the conversion of database on accdb mode????


    As i know we cannot open any form in design view after the conversion of database on accdb..!!


    What are we doing??

  10. #10
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270


    Accdb is "unconverted" format, I think If you meant accde? If so then bad luck, you can't do much with accde file.
    But you can just change actual value of text field on Form Open event instead of changing its default value.

  11. #11
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Ok. You are right my friend.

    But, as an idea:

    Lest say we have one form which includes one combo box (using as List box). We can give to combo box the values which we want as "Row Source" using a very simple code
    Me.cbo1.RowSource = Me.txt1
    Me.cbo1.Requery
    DoCmd.Save

    And then..... if there is a way on "Open Event" of the form the [cbo1] automatically to select the First Row (for example) this is gone a be a very simple and clever solution without to be necessary to give Default Value using the Design View of this form..

    What is your opinion??

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    See post # 7.

    Then if user changes the value in box, more VBA code can again set the DefaultValue with this new entered value for further records.
    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.

  13. #13
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Hi june7 and thank you for your attention.

    Maybe its is important to explain what exactly i need to do. Ok. With my poor English i will try to explain the whole idea.

    So, the idea is to create a solution about the best possible LOGIN SPLASH FORM without having any related table... So, all passwords must be embedded into a vba code so when i finish the database and after the conversion on accde, the forms couldn't be accessible on Design View so anybody can see the passwords..!!

    So, the Post7 there is nothing to do with this, because i don't have any table, records etc....

    Thats why i need a solution so to give me the chance to import my passwords somewhere as a default value

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What is this db for? Will there be any tables for data?

    Without tables or Design View, nothing can be saved. Period.
    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.

  15. #15
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    June7 the db is for a small company... Its a database of technical department

    There are some users (intranet connection) and any user has different permission..

    Any idea?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 02-28-2015, 06:52 PM
  2. Replies: 3
    Last Post: 06-20-2014, 02:30 PM
  3. Replies: 11
    Last Post: 10-22-2012, 08:39 AM
  4. Replies: 3
    Last Post: 07-20-2012, 11:41 AM
  5. Change Text field to Memo Field in a Query
    By Yarbz in forum Queries
    Replies: 5
    Last Post: 06-28-2012, 05:24 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