How to capture text form as a default value

  • Thread starter georgeof the jungle
  • Start date
G

georgeof the jungle

I am trying to find a way to capture text in a field on my form to be the
default value for a field in a record. Does anyone know how to do this in
Access 2003?
 
G

George Hepworth

The "default value" of a field in a form would be fixed at the time the
table is set up. For example, the default value for a date field capturing
the transaction date on a sale might be Date(), so as to always default to
the current date when recording new sales.

Why would you want to change that? Perhaps your goal can be accomplished
with a more appropriate method. But we would need to know what that goal is
to give you more guidance on how to get there.

George (of the city, but longing for the country)
 
M

Mr. B

While I agree with "George (of the city, but longing for the country)"
concerning needing a little more info, from the way you posted your question
it would appear to me that you are wanting to capture a current value in a
field on your form and when the next new record is created, use that value as
the value for that field in the new record.

If this is the case then I would suggest that you declare a Public variable,
at a module level. In a module place the following statement:

Public varDefaultVal as variant

Then use code in the after update event of the field in question to assign
the value provided in the file to your public variable. Like:

varDefaultVal = me.NameOfControl

Substitute the "NameOfControl" in the statement above with the actual name
of your control.

Then when the new record is created you can set the value of this same field
to the value stored in the Public variable. Use the On Current event of your
form and place the following code:

Me.NameOfControl = varDefaultVal

Again, substitute the "NameOfControl" in the statement above with the actual
name of your control.

All of the above lines of code are "air code" and as such are completely
untested.

If you are simply moving to a new record and not closing the form before
moving to the new record then there is one other way that you could do this.
You could store the value of your control (field) in the "Tag" property of
either the form or the control that you are wanting to use the value of as
the default for the new record.

I would most likely use the "Tag" property of the control because in the
event that you wanted to do this with more than one field you can do the same
thing for as many fields (controls) as you need.

To do it this way, use the following line of code in "After Update" event of
the control:

me.NameOfControl.tag = Me.NameOfControl

Then place the following line of code in the "On Current" event of the form:

Me.NameOfControl = me.NameOfControl.tag

Substitute the "NameOfControl" in the statement above with the actual name
of your control.

This should assign the previous value of the control as the value for the
new record.

All of this is based on the presumption that I understood what you wanted to
do in the first place. If I misunderstood please just post back and someone
will try to help.

-----
HTH
Mr. B
http://www.askdoctoraccess.com/
Doctor Access Downloads Page:
http://www.askdoctoraccess.com/DownloadPage.htm
 
G

georgeof the jungle

The user must log on to the database application. I want to capture their
logon ID and make it a part of the record they create. I am already
capturing the current Date/Time using the Default Value "Now()". The Logon
information shows up in two forms, "frmMainMenu" and "frmLogon", which is a
subform of the Main Menu. I tried using the expression
'=Environ("UserName")' but get an error message saying it can't find it when
I try to save the change. Any idea on how I can do this before I run out of
vines to swing on? (Considering the rate at which the jungle is getting
smaller).
 
J

Jeff Boyce

I'm with George ... I don't have enough information to know which way to
guide you.

I can imagine a couple different ways to interpret your description ... and
only one of them seems to match the response you got from Mr. B.

More info, please!

Regards

Jeff Boyce
Microsoft Access MVP
 
G

georgeof the jungle

Jeff,
The user must log on to the database application. I want to capture
their
logon ID and make it a part of the record they create. I am already
capturing the current Date/Time using the Default Value "Now()". The Logon ID
shows up in two forms, "frmMainMenu" and "frmLogon", which is a
subform of the Main Menu. The record they create is done using another
subform of the Main Menu. I tried using the expression
'=Environ("UserName")' for the Default Value, but get an error message saying
it can't find it when
I try to save the change. Any idea on how I can do this before I run out of
vines to swing on or hair to pull out?
 
G

George Hepworth

Gotcha,

Instead of trying to set the default value for a control, which not just
retrieve the Login whenever you need it?

You could, for example, use the venerable, FOsUserName()
http://www.mvps.org/access/api/api0008.htm

Another option, which I have seen used, it to capture values you want, such
as this one, in a hidden form at start-up. That form remains open, but
hidden, as long s the user's session is active and you can refer to that
control as needed.

LogInID = Forms!frmHiddenVariables.txtLogInID

HTH

George
 
G

georgeof the jungle

George,

The first one you suggested captures the Operating System Logon ID. Since I
am trying to capture the application logon ID (RE: Microsoft Jet Security),
I tried the second option, making by Logon form (frmLogon) a hidden file with
no luck. I'm completely puzzled by this one. Any other suggestions?
 
H

Hans Up

georgeof said:
The first one you suggested captures the Operating System Logon ID. Since I
am trying to capture the application logon ID (RE: Microsoft Jet Security),
I tried the second option, making by Logon form (frmLogon) a hidden file with
no luck. I'm completely puzzled by this one. Any other suggestions?

If you have applied Access user level security to your database, and you
want the ULS name of the current user, try the CurrentUser() function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top