dont save a form's fields until a button is clicked

R

reservedbcreater

is there a way i can make it so they can fill out a form but it doesnt save
it to the table until they click the next button to go to next form of the
survey?????

i want this because if i was just to show someone the form(ie open it, i
coded it to assign an ID # to ID field upon opening). and then after
showing the person the form, just closed it, it would still save a record
in the table with the newly assigned ID# and all the other fields blank.
 
R

reservedbcreater

i fixed this with
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim intResponse As Integer

intResponse = MsgBox("Save Record?", vbYesNoCancel)

Select Case intResponse
Case vbYes
'Do Nothing
Case vbNo
Me.Undo 'To undo the edit
Case vbCancel
Cancel = True 'To cancel the update & hence the close
End Select

End Sub
 
J

John Vinson

is there a way i can make it so they can fill out a form but it doesnt save
it to the table until they click the next button to go to next form of the
survey?????

i want this because if i was just to show someone the form(ie open it, i
coded it to assign an ID # to ID field upon opening). and then after
showing the person the form, just closed it, it would still save a record
in the table with the newly assigned ID# and all the other fields blank.

You can put code in the Form's BeforeUpdate event to check to see if
it's valid to save. For instance you could put a statement

Dim bOkToClose As Boolean

before the first Sub in the Form's module; set this variable to False
in the form's Current event, and to True in the click event of your
"save" button. Then in the Form's BeforeUpdate event put something
like

Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim iAns As Integer
If Not bOkToClose Then
iAns = MsgBox("Please use the Save button, or select " _
& " Cancel to erase this screen", vbOKCancel)
Cancel = True
If iAns = vbCancel Then
Me.Undo
End If
End If
End Sub

John W. Vinson[MVP]
 

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