How to reduce the option to save a record to a button only.

R

Rob Hofkens

Hello everyone :)

I think this has been asked many times and I already found some code, but
somehow it doesn't work and it doesn't cover everything.

I have a very simple form with 2 textboxes and I only want the users to do
this:
1) Fill in the 2 textboxes.
2) "Save" button to save the record.
3) "Exit" button to exit the form (cancel the add if not saved before)

I found code to disable the PgDn and PgUp keys but it doesn't work somehow :

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 33, 34
'If KeyCode is PAGEUP or PAGEDOWN then nullify them
KeyCode = 0
End Select
End Sub

I think I miss something but don't know what ?
I already spend a lot of time on this fairly simple thing.

Hope someone can help here :)

Thanx in advance !

Rob.
 
J

John Nurick

Hi Rob,

Access's natural way of working is to save new or edited records
automatically as soon as the user moves to another record or closes the
form.

If you want users to be able to enter new records but not view or change
existing ones, set the form's DataEntry property to True.

It's not very simple to set up "Save" and "Exit" buttons the way you
want. Would it be all right instead to have the a message box asking the
user whether or not they want to save the record?

If so, use the form's BeforeUpdate event. VBA code like this in the
event procedure should do the job:

Dim Answer As Long

Answer = MsgBox("Do you want to save the record" & vbCrLf _
& "you have just entered", vbYesNo + vbQuestion)

If Answer = VBNo Then Cancel = -1
 
R

Rob Hofkens

Hi John :)

I guess me "fairly simple thing" isn't simple at all.
Using the BeforeUpdate is another aproach but sounds good.

Thanx for your answer!

Rob.
 

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