Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2014
    Posts
    7

    Question Unanswered: How to make it compulsory to fill some gaps in database in access ?

    Hello every one ..

    How can i make it compulsory to fill some gaps in microsoft access database ?
    Please help
    Last edited by abdo SA; 07-24-14 at 05:46.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    fill some gaps?
    no idea of what you are looking to do

    do you mean
    missing numbers in a sequence (such as an invoice no or goods received note?
    missing columns in a row (record)?
    or something else?
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2014
    Posts
    7
    i mean there is some information i have to fill it first then go to the order details .. i need to make this information cumpolsory and fill it first before going to the order itself ..
    thank you ...

  4. #4
    Join Date
    Jul 2014
    Posts
    7
    like to make it a key .. it has to be wriiten before going any further ...

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    several wasy to do this
    first put some validations on you column definitions
    and or disable NULLS

    or validate your data in the forms before update event to ensure sane data is entered
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    There are a number of ways to approach healdem's last suggestion, depending on how many Controls you're looking to validate. To validate a few Controls:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
     If Nz(Me.Control1,"") = "" Then
       MsgBox "Control1 Must Not Be Left Blank!"
       Cancel = True
       Control1.SetFocus
       Exit Sub
     End If
     
    If Nz(Me.Control2, "") = "" Then
       MsgBox "Control2 Must Not Be Left Blank!"
       Cancel = True
       Control2.SetFocus
       Exit Sub
     End If
    
    End Sub


    You could loop through all or some 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
                  Exit Sub
                 End If
        End Select
    Next ctl
    
    End Sub


    You could also use the Tag Property to mark certain Controls, and then loop through all Controls but only check on/address the status of these 'marked' Controls.

    To set the Tag Property for multiple Controls, all at once:
    1. Go into Form Design View
    2. Holding down <Shift> and Left clicking on each Control in turn.
    3. Go to Properties Other and enter Marked in the Tag Property (just like that, no Quotation Marks)

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    Dim ctl As Control
    Dim CName As String
    
    
    For Each ctl In Me.Controls
      If ctl.Tag = "marked" Then
         If Nz(ctl, "") = "" Then
           CName = ctl.Controls(0).Caption
           MsgBox "Following field is required: " & vbCrLf & vbCrLf & CName
           Cancel = True
           ctl.SetFocus
           Exit Sub
         End If
       End If
    Next ctl
    
    End Sub


    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Join Date
    Jul 2014
    Posts
    7
    Thnak you so much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •