Save Value with Form

CT Witter

MrExcel MVP
Joined
Jul 7, 2002
Messages
1,212
I think I know the answer but I will pose it anyway. I want to have a textbox that I can manipulate the default value, and then save, so when the form reopens it uses the new default value. The default value will be a number.

For example, I open the form with default value of 5. Then change some data, new default is 3. I need to save this so when the form reopens, the default is 3.

here is what I'm currently using but it doesn't seem to work.

Code:
Dim recounter As Integer
recounter = Me.RecalcCounter.Defaultvalue
recounter = recounter - 1
Me.RecalcCounter.Defaultvalue = recounter
DoCmd.Save acForm, Me.name
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Just off the top of my head, here is how I would try to approach it. Create a one record table where you store this default value. Then access this lst record in this table to set/change the default value.
 
Upvote 0
I would have thought that your technique would work also...but, admittedly, I always use the method that jmiskey quoted. A table named similarly to 'tblDefault' seems to be in a lot of my mdb's.

For grins and anybody else searching for a solution, I wrote up a few quickie functions to work with that table.

Code:
Public Function FindDefaults(ByVal MyDefaults As String) As String

Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Select * from tblDefaults", dbOpenSnapshot)

With rst
    .FindFirst "TypeOfDefault='" & MyDefaults & "'"
    If !TypeOfDefault = MyDefaults Then
        FindDefaults = !DefaultInfo
    Else
        MsgBox "Information Not Found"
    End If
End With

Set rst = Nothing
Set dbs = Nothing

End Function

Public Function SetDefaults(MyDefaults As String, strEntry As String, strMod As Integer)
Dim dbs As DAO.Database
Dim rs As DAO.Recordset

Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("Select * from tblDefaults", dbOpenDynaset)

With rs
  .FindFirst "TypeOfDefault='" & MyDefaults & "'"
  If !TypeOfDefault = MyDefaults Then
      .Edit
      .Fields(strMod).Value = strEntry
      .Update
    Else         'If can not find it, create a new one
      .AddNew
      .Fields(0).Value = MyDefaults
      .Fields(strMod).Value = strEntry
      .Update
  End If
End With

Set rs = Nothing
Set dbs = Nothing

End Function

Mike
 
Upvote 0
Thanks for the suggestions.
That's what I thought.

I have in the past included it in a custom database property, but was looking for something that would be a little harder to find/access then the db properties or tables.


Thank you for your suggestions.
CT
 
Upvote 0

Forum statistics

Threads
1,221,821
Messages
6,162,157
Members
451,750
Latest member
pnkundalia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top