help: event happening when its not supposed to

R

reservedbcreater

i need to change my code so that the
Private Sub Command75_Click()
event doesnt happen unles the user chose "yes"
when prompted to save record, because then they choose cancel or no to not
save the code and i need it to stay on the current form, the
Command75_click() closes the current form and opens the enxt one.

here is my current code:


Private Sub Form_Load()

Dim strNextNumber As String

strNextNumber = Nz(DMax("ID", "General Housing Survey"), 0) + 1
Me.ID = strNextNumber

End Sub
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
Private Sub Command75_Click()
On Error GoTo Err_Command75_Click

Dim strDocName As String
Dim strID As String

If intresponseall = yes Then
strDocName = "Water"
strID = Me.ID
DoCmd.Close
DoCmd.OpenForm strDocName
Forms(strDocName)!ID = strID
End If


Exit_Command75_Click:
Exit Sub

Err_Command75_Click:
MsgBox Err.Description
Resume Exit_Command75_Click



End Sub
 
R

reservedbcreater

i got it working but i get an error message, when i choose to not save the
record and then close the survey....it reads.....ms access cannot find the
form "water" referred to in a macro expression or visual basic code. but
what i want to happen works, its just i get that message.

here is my code:

Option Compare Database
Private Sub Form_Load()

Dim strNextNumber As String

strNextNumber = Nz(DMax("ID", "General Housing Survey"), 0) + 1
Me.ID = strNextNumber

End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim strDocName1 As String
Dim intResponse As Integer
strDocName1 = "Water"

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

Select Case intResponse
Case vbYes
intResponse2 = MsgBox("Go to next page", vbYesNo)
Select Case intResponse2
Case vbYes
DoCmd.OpenForm strDocName1
End Select
Case vbNo
Me.Undo 'To undo the edit
Case vbCancel
Cancel = True 'To cancel the update & hence the close
End Select

End Sub
Private Sub Command75_Click()
On Error GoTo Err_Command75_Click

Dim strDocName As String
Dim strID As String


strDocName = "Water"
strID = Me.ID
DoCmd.Close

Forms(strDocName)!ID = strID



Exit_Command75_Click:
Exit Sub

Err_Command75_Click:
MsgBox Err.Description
Resume Exit_Command75_Click
 

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