Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allow User to Permanently Change a Default Value?

Status
Not open for further replies.

number2

Technical User
Oct 25, 2001
284
US
Is there any way I can allow a user to change a default value without going into design view in runtime?

I would like to allow users to be able to change the default value (table level default)to a default value of their entry.

Thanks!
 
How are ya number2 . . . . .

[purple]I would never allow users to change defaults![/purple] . . . . But if you must . . .

Here's a global routine from my library that should do the trick. Just [blue]supply the arguements[/blue] in the call. Put the code in a [purple]module[/purple] in the [purple]modules window[/purple]:
Code:
[blue]Public Sub SetDefault([purple][b]tblName[/b][/purple] As String, [purple][b]fldName[/b][/purple] As String, [purple][b]DefVal[/b][/purple])
   Dim dbs As Object, db As DAO.Database
   Dim fld As Field, Prp As Property, Typ As Integer
   Dim Msg As String, Style As Integer, Title As String, DL As String
   
   Set dbs = Application.CurrentData
   DL = vbNewLine & vbNewLine
   
   If dbs.AllTables(tblName).IsLoaded Then
      Msg = "Default can't be set at this time!" & DL & _
            "Table '" & tblName & "' is in use!" & DL & _
            "Close the table & try again . . ."
      Style = vbInformation + vbOKOnly
      Title = "Can't Set Default! . . ."
      MsgBox Msg, Style, Title
   Else
      Set db = CurrentDb()
      Set fld = db.TableDefs(tblName).Fields(fldName)
      Set Prp = fld.Properties("DefaultValue")
      Typ = fld.Type
      
      If Len(Trim(DefVal) & "") > 0 Then
         If Typ = dbText Then 'Text
            Prp = """" & DefVal & """"
         ElseIf Typ = dbDate Then 'Date/Time
            Prp = "#" & DefVal & "#"
         Else
            Prp = Val(DefVal) 'Numeric
         End If
      Else
         Prp = "" 'No Data
      End If
      
      Set Prp = Nothing
      Set fld = Nothing
      Set db = Nothing
   End If
   
   Set dbs = Nothing
 
End Sub[/blue]
[blue]Thats it . . . give it a whirl & let me know . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
I will give it a try Ace, thanks!
Here's the sistuation, I think it is less dramatic that you expect!
In a form which is used as a report editor, I have fields for Section Headers in the report. (a large medical legal report)

I need the users to be able to permanently change the headings to their particular need. ie. History, Examination Findings, etc. Make sense?
 
Ace, do I use this as a Function? How do I call it?
 
It could be installed peer to peer. The db is split.
 
number2 said:
[blue]It could be installed peer to peer. The db is split.[/blue]
[purple]This makes changing Table Defaults impractical . . . .[/purple]

Since were talking multiuser, an additional schema has to be added:
[ol][li][blue]Users have to be identified[/blue] (possibly at more than one peer station).[/li]
[li]A method to [blue]save, recall, amd modify[/blue] defaults per user, per peer station. Saving will involve an additional table on the Front End of each peer station, holding fields for UserID & appropriate Defaults.[/li][/ol]
As you can see, networking has turned this into a little more than you may have expected. . . . .

[blue]If you want the easyway out . . . consider comboboxes for those specific fields . . .
[/blue]

[purple]Your Thoughts?[/purple]

Calvin.gif
See Ya! . . . . . .
 
Yes..Perhaps a como box would be best..but the user would still have to select from the combo. I will look into that!

Cheers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top