Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2007
    Posts
    13

    Unanswered: Forms: Checking for empty fields

    OK, I have got my SQL working now for searches. What I want to do now is check a field for input.

    The form as all the controls on it and I want to make sure that everyfield as some sort of input.

    If the user has not entered anything into the field than I want a default value to be put in. I tried without sucess the following

    Code:
    If Me.HDDSize.Value = "" Then
    Me.HDDSize.SetFocus
    Me.HDDSize.Text = "123"
    End If
    This didnt work! I know there must be a way! (apart from settign required in the table property)

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    First try setting the default value of the control to what you want, usually a zero-length string works for me.

    Else, you can validate the entry from code, like you're trying. But do like...
    Code:
    If IsNull(Me.HDDSize) or Me.HDDSize = "" Then
         Me.HDDSize = "123"
    End If
    Me.Geek = True

  3. #3
    Join Date
    Feb 2007
    Posts
    13
    yea used this, works fine!

    Found a way with this code cheers. I know its cheating but it works!

    Code:
    'checks the searcable fields on the form and if empty, enters some default values
    'This will allow the searches to return all fields.
    
    'setup error routine
    On Error Resume Next
    
    'hard disc
    If IsNull(Me.HDDSize.Value) Then
    Me.HDDSize.SetFocus
    Me.HDDSize.Text = "Unknown"
    Me.cmd_next.SetFocus
    End If
    
    'IP Address
    If IsNull(Me.txt_IP.Value) Then
    Me.txt_IP.SetFocus
    Me.txt_IP.Text = "Unknown"
    Me.cmd_next.SetFocus
    End If
    
    'OS Selection
    If IsNull(Me.OS.Value) Then
    Me.OS.SetFocus
    Me.OS.ListIndex = 4
    Me.cmd_next.SetFocus
    End If
    
    'Processor type
    If IsNull(Me.com_processor.Value) Then
    Me.com_processor.SetFocus
    Me.com_processor.ListIndex = 6
    Me.cmd_next.SetFocus
    End If
    
    'User now
    If IsNull(Me.txt_user_now.Value) Then
    Me.txt_user_now.SetFocus
    Me.txt_user_now.Text = "No User"
    Me.cmd_next.SetFocus
    End If
    
    'User Next
    If IsNull(Me.txt_user_next.Value) Then
    Me.txt_user_next.SetFocus
    Me.txt_user_next.Text = "No User"
    Me.cmd_next.SetFocus
    End If
    
    'RAM
    If IsNull(Me.RAM.Value) Then
    Me.RAM.SetFocus
    Me.RAM.ListIndex = 9
    Me.cmd_next.SetFocus
    End If
    
    
    'LI Version
    If IsNull(Me.txt_version_sw.Value) Then
    Me.txt_version_sw.SetFocus
    Me.txt_version_sw.Text = "Version Unknown"
    Me.cmd_next.SetFocus
    End If

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    or simpler still:

    Set the textbox format to:
    @; "Empty"

    - GeorgeV
    George
    Home | Blog

  5. #5
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,424
    Provided Answers: 8
    I use the Table Properties

    set the Required to yes
    put some text in the valiation text
    and check with the validation rule
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  6. #6
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    How about using a delimited value in the tag attribute for textboxes you want to evaluate? The following untested snippet would assume you have textbox controls with tag properties similar to "validate; Enter Username" or "Validate; Unknown"

    Code:
    Dim valid As Boolean
    
    Dim ctl As Control
    Dim attr() As String
    
    valid = True
    
    For Each ctl In Me.Controls
        If ctl.ControlType = acTextBox Then
            attr = Split(ctl.Properties("tag"), ";")
            If attr(0) = "validate" And Nz(ctl, "") = "" Then
                valid = false
                ctl = attr(1)
            End If
        End If
                
    Next ctl
    
    if valid = true then
       'do whatever else it is you were planning here
    else
      'do whatever is global in the event of failing validation here
    end if
    Last edited by Teddy; 02-08-07 at 15:11.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

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