Updating a form with fields required

yetstar

Registered User.
Local time
Today, 12:38
Joined
Aug 8, 2007
Messages
18
I've got this code from searching through the threads here, but when I use it, the relevant messageboxes pop up, great, but then the form wont go to the next record....it just remains stationary.

Any ideas? I think my Else's and my Endifs are in the wrong place. I've been pulling my hair out over this, any help would be greatly appreciated :)

(I took the error handlers out for now to make things easier - I'll put them back in once I've clocked the coding :) )

Code:
Private Sub cmdAddRecord_Click()

If Me.Status.Value = "Closed" Then

If Me.P_Ref.Value & "" = "" Then
Cancel = True
MsgBox "Please ensure the P Ref field is complete", vbInformation
End If

If Me.No_Users_Reported_Affected.Value & "" = "" Then
Cancel = True
MsgBox "Please ensure the No Users Reported Affected field is complete", vbInformation
End If

If Me.Date_Time_Resolved.Value & "" = "" Then
Cancel = True
MsgBox "Please ensure the Date Time Resolved field is complete", vbInformation
End If

Else

DoCmd.GoToRecord , , acNewRec
End If

End Sub
 
Last edited:
I've got this code from searching through the threads here, but when I use it, the relevant messageboxes pop up, great, but then the form wont go to the next record....it just remains stationary.
When you click the button, if you get any messages at all, then you won't go to the next record. That's the way the code is written. Here are some notes:
Code:
Private Sub cmdAddRecord_Click()

If Me.Status.Value = "Closed" Then [color=red]'Outside IF BLOCK started[/COLOR]

If Me.P_Ref.Value & "" = "" Then
Cancel = True
MsgBox "Please ensure the P Ref field is complete", vbInformation
End If

If Me.No_Users_Reported_Affected.Value & "" = "" Then
Cancel = True
MsgBox "Please ensure the No Users Reported Affected field is complete", vbInformation
End If

If Me.Date_Time_Resolved.Value & "" = "" Then
Cancel = True
MsgBox "Please ensure the Date Time Resolved field is complete", vbInformation
End If

Else [color=red]'If Me.status.Value does [B][U]not[/U][/B] equal "Closed", then your code starts running here[/color]

DoCmd.GoToRecord , , acNewRec
End If [color=red]'Outside IF BLOCK ended[/color]

End Sub
In other words, your code will never execute the message box action and the GoToRecord action on the same click of the button.
 
Also note that Cancel = True will do nothing either, in this setting! All events that can be canceled in Visual Basic have a Cancel argument, such as:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If the argument doesn't appear when Access generates the sub, you can't cancel the particular event. You can't force it, either, by inserting the argument in an event that doesn't have it. This type of validation code is usually found in the Form_BeforeUpdate event which, I suspect, was where this code originally resided.

Linq
 
This is probably what you were meaning to write. :-

Code:
If Me.Status.Value = "Closed" Then
    If Me.P_Ref.Value & "" = "" Then
        MsgBox "Please ensure the P Ref field is complete", vbInformation
        Exit Sub     
    End If

    If Me.No_Users_Reported_Affected.Value & "" = "" Then
        MsgBox "Please ensure the No Users Reported Affected field is complete", vbInformation
        Exit Sub
    End If

    If Me.Date_Time_Resolved.Value & "" = "" Then
        MsgBox "Please ensure the Date Time Resolved field is complete", vbInformation
        Exit Sub
    End If
Else
    DoCmd.GoToRecord , , acNewRec
End If
End Sub

Toby
 
Thanks for all the replies guys, I'll have a look now and check it out (and yeah it seems so simple when you put it like that!)

Also note that Cancel = True will do nothing either, in this setting! All events that can be canceled in Visual Basic have a Cancel argument, such as:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If the argument doesn't appear when Access generates the sub, you can't cancel the particular event. You can't force it, either, by inserting the argument in an event that doesn't have it. This type of validation code is usually found in the Form_BeforeUpdate event which, I suspect, was where this code originally resided.

Linq

Dead on Linq, but when it was in the Form_BeforeUpdate event, it seemed that the code would either stop the update, ask for the relevant fields to be updated and then refuse to budge, or simply go on to the next record without asking for the required fields to be completed....

I'll have a go with it now though, and if it works I'll try again with it in the Form_BeforeUpdate event :)

Cheers
 
:(

So I try completing the form leaving one field blank. Great, it gives me the relevant message.

I fill in the required field, and click the next record button........and nothing happens.

Can anyone see where I'm going wrong?

Here's the code:

PHP:
Private Sub cmdCloseForm_Click()

If Me.Status.Value = "Closed" Then

If Me.P_Ref.Value & "" = "" Then
MsgBox "Please ensure the P Ref field is complete", vbInformation
Exit Sub
End If

If Me.No_Users_Reported_Affected.Value & "" = "" Then
MsgBox "Please ensure the No Users Reported Affected field is complete", vbInformation
Exit Sub
End If

If Me.Date_Time_Resolved.Value & "" = "" Then
MsgBox "Please ensure the Date Time Resolved field is complete", vbInformation
Exit Sub
End If

Else

DoCmd.GoToRecord , , acNewRec

End If

End Sub


The code only seems to go to the Else, when the Status.Value is not 'Closed' - what I need it to do is go to there once all of the required fields are completed.

I'm sure theres a really simple answer to this....
 
Last edited:
Worked it out :)

Checkit.....

Code:
Private Sub cmdAddRecord_Click()

If Me.Status.Value = "Closed" Then

If Me.P_Ref.Value & "" = "" Then
MsgBox "Please ensure the P Ref field is complete", vbInformation
Exit Sub
Else

If Me.No_Users_Reported_Affected.Value & "" = "" Then
MsgBox "Please ensure the No Users Reported Affected field is complete", vbInformation
Exit Sub
Else

If Me.Date_Time_Resolved.Value & "" = "" Then
MsgBox "Please ensure the Date Time Resolved field is complete", vbInformation
Exit Sub
Else


    DoCmd.GoToRecord , , acNewRec

End If
End If
End If
End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom