tab entry vs. command button entry

D

Daniel M

I have a form that has text boxes and combo boxes bount to a table. If i add
my data and tab all the way through the form it enters the data into the
table. I would like to change this behavior to require a command button to
enter the data.

I know i can unbound the form data and do something like this...

Dim Rs As Recordset
Set Rs = CurrentDb.OpenRecordset("Assets")
Rs.AddNew

Rs![Dateentered] = Dateentered
Rs![EmployeeID] = Employees
Rs![SerialNumber] = SerialNumber
Rs![DepartmentID] = DepartmentID.Value

Rs.Update
Rs.Close
Set Rs = Nothing

The problem with this is there are about 30 items on the form to fill out.
Is there a better way of doing this or this the best way?

Thanks.
 
J

Jeanette Cunningham

Hi Daniel,
there may be a better way. It would help if you would explain what it is
about your current form that makes you want a command button to enter the
data.
In access there are many different ways to set up forms and enter data,
different ones work better in some situations than others.
What do you mean by 'a command button to enter data' ?



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
L

Linq Adams via AccessMonster.com

"If i add my data and tab all the way through the form it enters the data
into the
table."

When you tab thru after the final control you're tabbing to a new record,
which saves the record you just left. The first thing to do is to stop this
behavior.

In Design View goto Properties - Other and set the Cycle Property to "Current
Record."
 
D

Daniel M

Changing the Cycle property is part of what i was looking for! Thanks.

Here is what i want on the form. Enter data, be able to tab through all
fields, click a command button to write the record. So far it all works ok.

the problem is if i fill out the form and close it before hitting the
command button to write the record all the data is written anyways. i assume
this is because the form fields are bound. is there anyway to stop this from
happening? I only want the command button to write the record.

dm.
 
L

Linq Adams via AccessMonster.com

Actually, if you enter data on a record and simply move to another record, it
will also be saved, and you can't really change this behavior with a bound
form, and you really don't want to go the unbound form route. That does away
with half the advantage of using Access.

You can add a "Save" button, if you like, the code's simple

If Me.Dirty Then Me.Dirty = False

but what you really need to do is to add code that asks your user if they
want to save the new/edited record.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If MsgBox("Would You Like To Save This New or Edited Record?", vbQuestion +
vbYesNo, "Save This Record ???") = vbNo Then
Me.Undo
Else
End If
End Sub

Now, whether they hit your "Save" button, move to another record, or close
the form, they'll be asked to confirm or reject the save.
 

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