Results 1 to 5 of 5
  1. #1
    Join Date
    May 2005
    Posts
    1,191

    Unanswered: Remember Control DefaultValue Between Form Openings

    Hey all,

    I have a form with a couple of controls on it, and I'm trying to make it "remember" what the user enters for the next time he/she opens the form.

    I've tried using Dev Ashish's approach, like so:
    Code:
        Dim frm As Form
        Dim ctl As Control
        
        'initiate variables
        Const cQuote = """"
        Set frm = Forms!frmName
        
        'Save defaults
        SysCmd acSysCmdSetStatus, "Saving Defaults..."
        Set ctl = frm!tboNumber1
        ctl.DefaultValue = cQuote & ctl.Value & cQuote
        'Debug.Print ctl.DefaultValue
        Set ctl = frm!tboNumber2
        ctl.DefaultValue = cQuote & ctl.Value & cQuote
        'Debug.Print ctl.DefaultValue
        Set ctl = frm!chkBox
        ctl.DefaultValue = cQuote & IIf(ctl.Value, "TRUE", "FALSE") & cQuote
        'Debug.Print ctl.DefaultValue
        DoCmd.Save acForm, frm.Name
    Immediately after the code is run, if I do a debug.print ctl.defaultvalue, it gives me whatever I have entered in the appropriate control, so I know the code is working. But for some reason, when I close the form, and then try to reopen it, it "forgets" the new defaults, and goes back to whatever defaults I had set manually previous to running the above code.

    Any ideas on how to make the form remember the defaults between openings?
    Me.Geek = True

  2. #2
    Join Date
    Sep 2002
    Location
    South Wales
    Posts
    580
    DoCmd.Save acForm, frm.Name

    frm.Name????

    <Not sure if you might have to do changes in "design view"
    (Try opening form in design view programatically if you have no joy)
    Windows Server 2003-8 / Terminal Services / SQL 2000 / Access 2003 / Office 2003-7 / Exchange 2003-7 / Blackberry Enterprise Server / AutoCAD / Lambert And Butler / Red Bull

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if you want to store the last used values in the form so it will display those the next time the form is used, then you need some form of storage mechanism to record what those values are.

    that means stuffing the data into a config table or if you wish to apply the same design style have a table which identifies the user, the form/report and the parameters as text say param = "userid='blah' and somethingelse='aaabjuh' and anumbervalue=96772

    another approach may be to put a userid and timestamp on the row in the table the form maintains. query the table for the the most recent row in the table for that user and use whatever parameters you see fit from that row as suggestions.
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    May 2005
    Posts
    1,191
    Thanks Healdem, I was afraid of that. I have a User Table already set up though along with Dev Ashish's fosusername(), so I think I can probably add a couple fields to that table to store the defaults, just a bit more work than I was hoping to get away with.
    Me.Geek = True

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if you are going down taht route then I'd suggest you store this sort of stuff in a sub/child table hanging off the user table. the reason?
    if the design stylistic works for you you may want to implement it on other forms or reports and then your original design could get clumsy.

    you coudl also make advantage of this sort of thing and dump other transient data about the user (eg if they run a set of reports with data limitatiosn on you coudl store those parameters there. you could also stuff some audit data (especially if you make the table write only ie no delete or updates allowed) so you could have an audit trail to knwo when a person did a specific activity you could track what they did. I'm thinking of things such as who ran what reports with what parameters. Its not neccesarily the 'right' place for an audit log (ie who accessed what records when and from what machine... but y'get the picture
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •