Modifying the default value of a field?

atisz

Registered User.
Local time
Today, 05:03
Joined
Apr 5, 2005
Messages
96
Hello!

The user has to introduce some data monthly in a table (600-800 records) and all this in 1-2 days. It would be more easyer for him if he don't has to enter for each customer the year and some other data (text) manually (they are the same for each customer). If the default value for those fields are set for the desired value , is Ok.But a user shouldn't have access to the database window. So, is it possible to do this automatically, using only the user interface of the database whithout modifying the default value in design view of a table?
Or is there any other solution?

Thanx!
 
Here's one approach, altering the default value of the form controls on the form where the user inputs data. To make it work, just put some "bogus" text in the .Tag property of the controls you wish to "carry over". Call it from the after update event of the form?
Code:
Dim ctl As Control
For Each ctl In Me.Controls
    If ((ctl.ControlType = acTextBox) Or _
        (ctl.ControlType = acComboBox) Or _
        (ctl.ControlType = acListBox) Or _
        (ctl.ControlType = acCheckBox)) Then

        If (Len(ctl.Tag & vbNullString) > 0) Then        
            Select Case True
                Case IsNull(ctl.Value)
                    ' If no value, don't change default value
                    ' this will need to be tweaked according to
                    ' requirements. Perhaps use "", so that the
                    ' “old” default value disappears…
                Case IsDate(ctl.Value)
                    ' Dates - hmmmm - because of different
                    ' regional settings (differing
                    ' from US date format) it is sometimes
                    ' necessary to do some formatting
                    ctl.DefaultValue = "#" & _
                        Format(ctl.Value, "yyyy-mm-dd") & "#"
                Case IsNumeric(ctl.Value)
                    ' No formatting for numbers
                    ctl.DefaultValue = ctl.Value
                Case Else
                    ' Then it should be text, four double quotes...
                    ctl.DefaultValue = """" & ctl.Value & """"
            End Select
        End If
    End If
Next ctl
 
I take it that the user uses an input form which you have designed.

I would put 2 text boxes in the form header for the desired constant data then in the on current event of the form code

Me.flda = me.txtflda
me.fldc = me.txtfldc

txtfldb being the name of the textbox containing the data for fldb

Brian
 
I had forgot something

Brianwarnock said:
I take it that the user uses an input form which you have designed.

I would put 2 text boxes in the form header for the desired constant data then in the on current event of the form code

Me.flda = me.txtflda
me.fldc = me.txtfldc

txtfldb being the name of the textbox containing the data for fldb

Brian


It's simple and it's working grate... but there is a problem. I had forgot to mention, that the values introduced are the same/month. So this default values are changing monthly, and the values enered before most remain unchainged (the new values entered are going to be default values just from the moment the user change them, and till the next month when he will change them again, but the data allready entered before has to remain unchanged).
 
Wasn't in the office Friday and was not on forum at all, at home on a wet Saturday so took a look, Would using the on current event for each field work for you, ie code Me.fldb=mem.txtfldb in fldb on current event etc and then the data would only change if you tab to or click on the field, it saves the typing.

Brian
 
Alternatively put a test into the form on current event
eg
If IsNull Fldb Or Fldb = " " Then
Me.Fldb=Me.txtFldb
End If

and repeat for other field

Brian
 
atisz,

So this default values are changing monthly

you should asked yourself what's the use to store data that is the same for all your customers.
Doesn't make sense....

RV
 
As I understand it the default values for NEW records each month are the same,but are different from those of previous entries, seems ok to me, but having got my brain into gear the Form on current event code should be, using my 1st post example,

If Me.Newrecord Then
Me.flda = me.txtflda
me.fldc = me.txtfldc
End If

Thus the automatic default will only apply to new records.

Brian
 
Thank you so much!

Brianwarnock said:
As I understand it the default values for NEW records each month are the same,but are different from those of previous entries, seems ok to me, but having got my brain into gear the Form on current event code should be, using my 1st post example,

If Me.Newrecord Then
Me.flda = me.txtflda
me.fldc = me.txtfldc
End If

Thus the automatic default will only apply to new records.

Brian


With this small modification it's working great! Thanx a lot.

Attila
 
Yes, it does!

RV said:
atisz,



you should asked yourself what's the use to store data that is the same for all your customers.
Doesn't make sense....

RV

It does make sense, if you have some calculations on your form that depends on this field(s).
More exactly: I have a form (with clients related data: name, address...) with 2 subforms.
Subform 1: clients service consumer related data (this are changing monthly);
Subform 2: price related data (price could be the same or diffrent from a month to other).
I use client ID to connect subform 1 to the form, and month (in a specific format), to connect subform 1 to subform 2.
 

Users who are viewing this thread

Back
Top Bottom