T
td
Looking for ideas on things that might be wrong w code for a button on a
form. I'll simplify the description a bit, but I think this should have the
main points. I'm not an expert programmer, so any suggestions on better ways
to do this are appreciated.
I have a database with a sequenial index number. A lot of what we do with
this database form involves users updating old data (i.e., existing records),
but sometimes there is a new record added to the database with a new index
number. Sometimes the new record is almost the same (except for one or two
fields) as the previous record, so I wanted a button that would copy all of
the rest of the data from the previous index number. Simple, right?
The button I made to solve this problem does the following: gets a recordset
from the previous record where index = index minus one, uses data from that
recordset to assign values to a few variables. Then an update statement is
executed for the current record (where index = index) to write those variable
to specific fields of the current record.
While debugging, I noticed that the button doesn't seem to work if the
starting record is a new record. It works fine for existing records, but
doesn't do anything when clicked while viewing a new record from the form.
You can defeat this error in some simple ways. If you create a record, go
back to a previous record, and then go forward to the new record again, then
the button works when clicked. There's something about the newness of a
freshly new record that won't let my code work though. I'm suspecting that
Access hasn't written a new record to the table yet, so that the update
statement doesn't go anywhere (the WHERE index = index# statement doesn't
return any records to be updated).
The weird thing is that it has worked a couple times with new data, so it's
a little sketchy. The first time I saw this, I thought maybe I should write
in a Save Record line of code prior to the rest of the button code running,
to make sure the record was written to the table. I couldn't find code for
Save Record, so I thought I'd try out just a Refresh command. I wrote that
Refresh command in there and it solved my problems... for about five minutes.
I kept testing my code, and it worked several times with new records, and
then started doing nothing again. Now it never works. V confusing.
Anyway, that's what I got. Any insight is greatly appreciated. In
particular, any idea how to issue a Save Record command within code? Or is
there a simple way to make Access write the data in the current record to the
table before it runs the rest of the button code?
Thx,
T
form. I'll simplify the description a bit, but I think this should have the
main points. I'm not an expert programmer, so any suggestions on better ways
to do this are appreciated.
I have a database with a sequenial index number. A lot of what we do with
this database form involves users updating old data (i.e., existing records),
but sometimes there is a new record added to the database with a new index
number. Sometimes the new record is almost the same (except for one or two
fields) as the previous record, so I wanted a button that would copy all of
the rest of the data from the previous index number. Simple, right?
The button I made to solve this problem does the following: gets a recordset
from the previous record where index = index minus one, uses data from that
recordset to assign values to a few variables. Then an update statement is
executed for the current record (where index = index) to write those variable
to specific fields of the current record.
While debugging, I noticed that the button doesn't seem to work if the
starting record is a new record. It works fine for existing records, but
doesn't do anything when clicked while viewing a new record from the form.
You can defeat this error in some simple ways. If you create a record, go
back to a previous record, and then go forward to the new record again, then
the button works when clicked. There's something about the newness of a
freshly new record that won't let my code work though. I'm suspecting that
Access hasn't written a new record to the table yet, so that the update
statement doesn't go anywhere (the WHERE index = index# statement doesn't
return any records to be updated).
The weird thing is that it has worked a couple times with new data, so it's
a little sketchy. The first time I saw this, I thought maybe I should write
in a Save Record line of code prior to the rest of the button code running,
to make sure the record was written to the table. I couldn't find code for
Save Record, so I thought I'd try out just a Refresh command. I wrote that
Refresh command in there and it solved my problems... for about five minutes.
I kept testing my code, and it worked several times with new records, and
then started doing nothing again. Now it never works. V confusing.
Anyway, that's what I got. Any insight is greatly appreciated. In
particular, any idea how to issue a Save Record command within code? Or is
there a simple way to make Access write the data in the current record to the
table before it runs the rest of the button code?
Thx,
T