Check if all fields in new row are filled in (1 Viewer)

yahoo

Registered User.
Local time
Today, 15:39
Joined
Jan 10, 2013
Messages
13
Hi there

I have a form with datasheet view and I need to make user that user fills in all fields before he moves on to the next row.
Any idea how to catch the moment of moving to another row?
/:banghead:
 

missinglinq

AWF VIP
Local time
Today, 10:39
Joined
Jun 20, 2003
Messages
6,423
If you’re doing this for more than one Control, you’ll have to include the line

Exit Sub

otherwise, if the first Control is empty, the code will drop down to check the next Control, not allowing the user to correct the omission in the first Control:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

 If Nz(Me.Control1,"") = "" Then
   MsgBox "Control1 Must Not Be Left Blank!"
   Cancel = True
   Control1.SetFocus
   [COLOR="Red"]Exit Sub[/color]
 End If
 
If Nz(Me.Control2, "") = "" Then
   MsgBox "Control2 Must Not Be Left Blank!"
   Cancel = True
   Control2.SetFocus
   [COLOR="Red"]Exit Sub[/color]
 End If

End Sub

You could loop through all Controls and do the same thing. If the above is too onerous, given your situation, this will loop through all Textboxes and all Comboboxes and check that they're populated
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim ctl As Control
Dim CName As String


For Each ctl In Me.Controls
    Select Case ctl.ControlType
        Case acTextBox, acComboBox
            If Nz(ctl, "") = "" Then
              CName = ctl.Controls(0).Caption
              MsgBox "Following field is required: " & vbCrLf & vbCrLf & CName
              Cancel = True
              ctl.SetFocus
              [COLOR="Red"]Exit Sub[/color]
             End If
    End Select
Next ctl

End Sub

Linq ;0)>
 

yahoo

Registered User.
Local time
Today, 15:39
Joined
Jan 10, 2013
Messages
13
well Ive done a lazy one :p

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

       If "" & Me.[Drawing Ref] = "" Or "" & Me.Grid = "" Or "" & Me.[Object type] = "" Or "" & Me.Status = "" Then
               MsgBox "Please enter data in all fields"
               Cancel = True
        End If

End Sub

Thanks for all help guys!

Any idea how to allow user to remove that row instead of filling it in?
 
Last edited:

Users who are viewing this thread

Top Bottom