Text box help

G

G.I.O.

Hello to all and thanks for taking the time to help me!

Creating a database form for my business and need some help with the
text box.

First, I'd like today's date to show up in the first box. I tried
placing the expression
"=Date()" for the vaulation rule but this does not seem to work. The box
is empty
with I go to forms view. What am I doing wrong, here?

Second, is it possible to have the text box for the next record
automatically take on what was typed in on the previous record so I do
not have to retype it. I have many records
that will follow each other with some identical information (locations,
etc.).
How would I do this?

Again, appreciate the help.

George
 
K

Ken Snell [MVP]

If you want that textbox to always display today's date, put this expression
in its Control Source property:
=Date()

If you want that textbox to start with the value of today's date, but allow
you to change it and/or save the actual date into your form's Record Source,
put this expression in its Default Value property:
=Date()

To have the next new record start with the value that was in the
last-entered record while the form remains open, use the AfterUpdate event
of the control to run this code:

Private Sub TheControlName_AfterUpdate()
Me.TheControlName.DefaultValue = """" & Me.TheControlName.Value & """"
End Sub
 
G

G.I.O.

Ken:

Problems...

After I used that code things went crazy. Now all my text boxes are taking the
previous record data not just the one I used the code for. Also, if I go back to
the previous record
the data from the record I'm on goes back too, cancelling out what I had there.

My value list (pick one) no longer works. I get an audible warning and nothing
is filled in.

I cannot seem to find that code now to remove it.

Help, please!
 
K

Ken Snell [MVP]

Post the actual code that you have in the form's module (all of it).

Also, what did you do for the Date() setup? Did you use the control source?
or the default value?
 
G

G.I.O.

I'm in over my head. I don't know where to get that code from. I'm using just
the properties
area by right-clicking on the specific text box under design form.

RE: the date... I got it to work with control source but could not change it. I
then tried default value but nothing would appear in form view so I'm back to
square one on the date.

George
 
K

Ken Snell [MVP]

? If you used the code that I'd provided before (the "Private Sub
TheControlName_AfterUpdate()" stuff), then you must have had the Visual
Basic Editor open to add that code?

Describe what steps you took using the information that I'd posted in the
first reply.
 
G

G.I.O.

OK.... maybe I did stumble on it not knowing what I was doing...

Right click on text box | data | default value | ... | <value> | AfterUpdate |
pasted in your code in top box | click OK.

However, going there now there is no code present. The box is blank but the
effect it has is still showing up in all the text boxes. Data is copied forward
and backwards over 3 records.

George
 
K

Ken Snell [MVP]

Is this what you did?

RightClick on textbox...selected Properties...clicked on Data....clicked
inside Default Value box. Typed in the expression:
=Date()

If you did the above as I've noted, then all new records will get the
current date as the initial value for that control in the new record.


And for the other item:

RightClick on textbox...selected Properties...clicked on Event...clicked
inside After Update box. Pasted in the code that I'd posted.

If this is what you did, then it's not right. Do this instead:

RightClick on textbox...selected Properties...clicked on Event...clicked
inside After Update box...select "[Event Procedure]" from the dropdown
box...click on "three-dot" button at far right side of the box. You'll see
these two lines (where "TheControlName" will be replaced by the actual name
of the textbox control) separated by a blank line:


Private Sub TheControlName_AfterUpdate()

End Sub


On the blank line, type this expression (except replace each instance of
"TheControlName" with the actual name of the textbox control):
Me.TheControlName.DefaultValue = """" & Me.TheControlName.Value & """"

Close the Visual Basic Editor. Save the form.

Now what happens when you use the form?
 
G

G.I.O.

The date thing does not work. There is no date in the text box when I switch to
view mode.

Doing as you have outlined for the code does not correct my problem. I still
have whatever I place in ANY text box showing up in the next record or if I go
backwords, the previous record.

Can you get me back to where I was this AM and I will just type in the data for
each record?

Also, is it possible to save the form layout I have created on one computer so
I can move it to another machine (via floppy) for use there? I cannot seem to
save it to a floppy for some reason.

Thanks,
George
 
K

Ken Snell [MVP]

Go back to a backup copy of the database that you made prior to making the
changes based on what we discussed. I have no way of seeing what that setup
was, nor what you've actually changed it to, from here.

It sounds as if your textbox is unbound (it's not bound to a field in the
form's RecordSource), and your using it on each record. When you use an
unbound textbox in a continuous forms view, that textbox will retain the
last-entered value...which shouldn't be a big problem here as it appears
that you're not storing that value anyway?

Perhaps you should start at the very beginning and describe the form's
layout, the recordsource for the form, the controls that are on the form,
the fields that are bound to those controls, etc.? That may assist us in
walking you through this setup.
 
G

G.I.O.

Back up copy. That would have been a good idea.

Yes, there is the word "unbound" in each text box on my design view if this is
what you mean.

I have 13 text boxes, 4 yes/no check boxes, one 4-position selection box. I
started by adding the names in Tables | Design. I then used Autoform to get me
to the form design section where I mearly rearranged the names and text boxes on
my page. Made some text boxes larger or longer. That's about it until today.
Fairly simply stuff.

I have one of these "Easy Access" books from Que. There is nothing about the
code stuff in there so I never knew I would need to go there.

George
 
G

G.I.O.

OK. I think I have fixed some of this.

I have added the "name" of each text box as the "control source" for that box and
all seems to be working correctly. The date shows up and I can now change it if I
want. Each record is clear until I add something.

I will now try and use the code you gave me earlier to see if I can get that one box
to copy forward.

George
 
G

G.I.O.

Tried that code again as you said and it does not seem to work. Does not copy the text
forward for that box. Here is what is on the "..." page: (Clearance is the name I'm
working with)

Option Compare Database
Option Explicit

Private Sub Category_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub Clearance_AfterUpdate()
Me.Clearance.DefaultValue = """" & Me.Clearance.Value & """"
End Sub

Private Sub Form_Load()

End Sub

Private Sub Label54_Click()

End Sub

Private Sub USCO_Search_Click()

End Sub
 
K

Ken Snell [MVP]

This code will not "copy forward" per se, but will cause a new record to
start with the "last-entered" value in that textbox. You will have to start
the new record in order for the "last-entered" value to be seen in that
record. Is this not working for you?
 
G

G.I.O.

Not sure what you mean. If I enter same text in the "clearance" text box and
then go up to the next record (from say record 3 to record 4) should I see the
very same text in the "clearance" box as was in record 3?

If no, what do I need to do to see the same text?
 
K

Ken Snell [MVP]

If record 4 is not being created at that exact moment that you "go to it",
then no, you won't see the same value in it as you typed into record 3.

Are you saying that you want all records to change their values whenever you
type a value into one record? That could be a very dangerous thing to code
in your form....
 
G

G.I.O.

Here is what I'm trying to end up with...

I'm on, say, record #155 and I type some data (a description) into a specific
text box called "clearance". As it turns out, the next record, #156, will need
to have the exact same data typed into it's own "clearance" text box. If I can
get that text from record 155 to "pop into" record 156 only for that one
"clearance" box then I can save having to retype it.

Now, like the thing we did for "date", if I get to a record, say #160, that
either has nothing for "clearance" or something completely new then when I start
to type in that box it will
allow me to either delete what's there or let me add the new text over the old.

If I delete the text from the "clearance" box on record #160 then #161 will also
be blank.

Nothing I do will alter the previous records. I can only "copy forward" one
record
and only for that one text box (or any box I set this up to work with).

Sound like it may be possible??

George
 
B

BruceM

I've been watching this thread, and am going to pop in for a moment and hope
that I don't muddy the waters. In a somewhat similar situation I had
something in the form's On Current event along the lines of:

If Me.NewRecord Then
Me.TheControlName.DefaultValue = """" & Me.TheControlName.Value & """"
End If

The middle part is, of course, the code Ken provided. I suppose this is
really more of a question for Ken than a suggestion that is ready to be
tried. As I understand it, you would want to carry the value forward only
when you are creating a new record.
 
K

Ken Snell [MVP]

Step back and ask yourself this question... how is ACCESS supposed to know
if you want the data from the previous record to be put into the next record
if that record already has a value (should it always replace it? should it
replace it only if it's blank? should it replace it only if the last entry
was manually changed in some very specific way? should it ask you each time
if it should replace a value? etc.)

Iif you want to manually decide when to "copy" the value from one record
into another, use the Keyboard Shortcut key already existing in ACCESS --
namely, Ctrl + '. This will copy down the value from the previous record to
the current record for that field. Will that meet your needs? Or you could
highlight the desired value in a record, use Ctrl + c to copy it, and then
paste it into other records.

My code that I'd provided was meant to be used for putting a "default value"
in a new record... it will have no effect on existing records.

If I'm still misunderstanding what you want, maybe we should start at the
beginning with some sample data and records... help us understand what the
"logic test" will be for ACCESS to know when and when not to replace an
existing value in an existing record.
 
K

Ken Snell [MVP]

Your thought about carrying forward the value into new records is what I had
been understanding... but I'm not sure that this is what G.I.O. actually
wants?

A default value will be put into a record only when a new record is being
created. Thus, it should be unnecessary to use the If...Then test that you
suggest.
 

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