Question Disable F5 reload functionality in Access Form?

Delinquent

New member
Local time
Today, 21:20
Joined
Apr 25, 2018
Messages
9
Hi,

does anyone know how to stop F5 reloading the form as its also adding an incomplete entry into the database?

I have a seperate button to add records and dont want this functionality. Been at this problem for the last couple of hours :banghead:

Kind regards!
 
Hi Pat,

Everything else works fine, my button to create new entries works perfectly. It's just this f5 business that seems to sidestep my button and the logic behind it and create the record itself.

I didn't know about f5 until my colleagued pressed it accidentally to reload the form and it entered an incomplete entry into the database. Is there no way to easily disable the f5 refresh?
 
Create a Macro.
On the right pane sekect Submacro.
Name the submacro {F5}
On Add new Action: Beep.

Save your macro as Autokeys.
Restart your app to take effect.
 
In the KeyDown event for every form where you want to call this, place this code:

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

    If KeyCode = vbKeyF5 then KeyCode = 0
    
End Sub
You will also need to set the form property "Key Preview" to Yes.
 
The difference between my solution and arnelgp's is that mine will only affect the forms where you insert the code, whereas his will affect the entire application.
 
The difference between my solution and arnelgp's is that mine will only affect the forms where you insert the code, whereas his will affect the entire application.

As there are many times when you are likely to want the Refresh capability, I would only disable it where absolutely necessary.
Therefore I recommend doing so using Frothy's approach
 
I stand by my original statement. You have code that is causing the problem. F5 does not in and of itself create new records.

I used the Access wizards to create the form and the new item button so I don't know where the broken code might have come from :/

Is there a known problem with the wizards for either of the above functions?
 
I used the Access wizards to create the form and the new item button so I don't know where the broken code might have come from :/

Is there a known problem with the wizards for either of the above functions?

Not that I'm aware of. I also agree with Pat's comment.
You need to step through your code to identify the issue
 
I'll amplify this. Using F5 cannot create a new record because all it does is a REFRESH. However, code in your form can do this in conjunction with F5 because F5 seeks to make the form "not dirty." The only two ways for Access to do this involve either triggering a SAVE (which is the default, because Access wants to SAVE rather than lose data) or triggering an UNDO (which isn't the default).

So the next question is, what makes the form dirty? To which the answer is, anything that runs automatically and can modify the content of any control. The answer is, two main places. If you have timer code running and that code could modify any controls, that's one possible culprit. The other likely candidate is the Form_Current code, which would be run after the F5 refresh occurs - because at that moment, the form has again become "current."

As to why it is a "new record" rather than updating the old record would depend on form settings and database settings.
 
Hi,

This is my database, I have removed the Macro to disable F5 and left in the macro changes that check if the textboxes are empty once the add record button is pressed.

To reproduce the issue simply enter data into one of the textboxes in the form and press f5. This creates a record in the database. I don't want the fields to be required in the database, as this tends to lock the form when you try to enter text and then make it blank and try to leave the form or click into another textbox.

Thanks for all your help so far on this :)
 

Attachments

Hi Pat,

thank you for having a look at my database and for the informative response, I really appreciate that :)

I would still want the save and maybe a cancel button but i'm unsure on how to add the save button since when I used:
Code:
Private Sub Save_Record_Button_Click()
    DoCmd.RunCommand acCmdSaveRecord
End Sub
I get an error "3021, no current record". Wouldn't I just need this to update the form for the validation code to be run and for the record to be created if the validation is passed?
 
When you have a properly bound form, there are very few times to NOT have a current record. One occurs if you delete the current record somehow and then your form fails to navigate correctly because you deleted the only extant record in the recordset. There are other rare cases, almost all of them (I DID say "almost") caused by trying to do too much or trying to do something in the wrong event.

If your form is used exclusively for new data entry, then your Form_Load (for the first time you open the form) and the After_Update (right after saving the previous record of intrest) routines might be the right place create a new, empty record for you. If your form can also be used for editing existing records, then a "NEW" button would be appropriate, since you like buttons. There is a command button wizard that will build the scaffolding for the NEW function. I'm with Pat on the idea of using an UNDO or CANCEL button. And yes, there is also a command button wizard for THAT function.
 

Users who are viewing this thread

Back
Top Bottom