General discussion

Locked

Force action on a form

By carljohnman ·
I have the code below inserted for a command button called "next" which brings up the second form in order to enter data. I was hoping someone could tell me where and how to NOT allow this action to occur unless the user saves the record first (I placed a save record command button on the same form with the "next" command.)
So, if you are a user you can enter data into the form but until you save it, you will not proceed. Thanks in advance for any help.

Private Sub Command28_Click()
On Error GoTo Err_Command28_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Probatedb Test Form1"
DoCmd.OpenForm stDocName, acNormal, , , , , Me![Probatedb TestID]

DoCmd.Close acForm, Me.Name

Exit_Command28_Click:
Exit Sub

Err_Command28_Click:
MsgBox Err.Description
Resume Exit_Command28_Click

End Sub

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Force action on a form

by nikki96 In reply to Force action on a form

Make a global variable (boolean) that is false if the 'save' button has not been clicked and true if it has. The global var's scope is this form. (put it at the top before any subs)
When the user clicks the 'next' button, check the global var. If false, pop up an error and exit. If true, proceed with the code to open the next form.

HTH
Nikki

Collapse -

Force action on a form

by carljohnman In reply to Force action on a form

I am not rejecting this answer because of your answer, I simply do not know any other way to reply. It is my fault I did not clearly state I am a newbie to code and although your logic makes sense to me I do not know how to write this code and exactly where to insert it. Could you please be kind enough to be more detailed and show me a example I could use in my form? I apologize for not being more clear about my experience and hope you have time to reply.

Thank you for this input and any further in advance,
Carl

Collapse -

Force action on a form

by nikki96 In reply to Force action on a form

Ok, all the way at the top of the form code, before any subs or anything but after the Option Explicit statement (if you have one), put this.

Dim okay as Integer
okay = 0

Then, in the code for the save button, put this.

okay = 1

Then, in the code for the next button, put this. I assume the next button is the Command28?

Private Sub Command28_Click()
On Error GoTo Err_Command28_Click
Dim stDocName As String
Dim stLinkCriteria As String

If okay = 0 Then
MsgBox "Error!" 'or whatever you want the error message to be
GoTo Exit_Command28_Click
Else
stDocName = "Probatedb Test Form1"
DoCmd.OpenForm stDocName, acNormal, , , , , Me![Probatedb TestID]
DoCmd.Close acForm, Me.Name
End If

Exit_Command28_Click:
Exit Sub

Err_Command28_Click:
MsgBox Err.Description
Resume Exit_Command28_Click

End Sub


I can't test this for syntax errors, since I don't have the associated controls defined. So if you have any problems, let me know.

Hope it helps,
~Nikki~

Collapse -

Force action on a form

by carljohnman In reply to Force action on a form

Your input is greatly appreciated. Thank you very much for taking time to come up with a solution. I just want to mention I inserted:

If Me.Dirty Then
MsgBox "Please click on the Save Button", vbOKOnly
Else

stDocName = "Probatedb Test Form1"
DoCmd.OpenForm stDocName, acNormal, , , , , Me![Probatedb TestID]
DoCmd.Close acForm, Me.Name
End If

and this seems to work great, as always there is many ways to do something.
Again, Thanks for all the help!

Carl

Collapse -

Force action on a form

by carljohnman In reply to Force action on a form

This question was closed by the author

Back to Software Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums