Results 1 to 5 of 5
  1. #1
    trevor40's Avatar
    trevor40 is offline Advanced db Manager
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    402

    check 4 text boxes, if any empty change label to red for it

    I'm having a metal block,

    I need to check if any of 4 text boxes haven't been completed and for the ones that have no data change the label to red.
    I have this...

    If IsNull(Me.From_Company) Then
    t = MsgBox("A required field has not been completed !" & vbCrLf & vbCrLf & "Fields
    shown in red require an entry", vbOKOnly, "Required feilds are empty !")
    Me.From_Label.ForeColor = 255
    exit sub
    end if



    how can I do this to any of the 4 fields? and continue if all are ok, if not return to the form

    I'm think I have to make an array of the field names and loop through it, any ideas?

  2. #2
    trevor40's Avatar
    trevor40 is offline Advanced db Manager
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    402
    Posted too soon, this works ok. unless sombody can offer a better way to do this?


    [code]
    If Not IsNull(Me.Consignment_Note_Number) Then Me.Consignment_Note_Number_Label.ForeColor = 16777215
    If Not IsNull(Me.From_Company) Then Me.From_Label.ForeColor = 16777215
    If Not IsNull(Me.To_Company) Then Me.Label47.ForeColor = 16777215
    If Not IsNull(Me.Courier) Then Me.Label22.ForeColor = 16777215
    If Not IsNull(Me.addressed_to) Then Me.Label45.ForeColor = 16777215
    If IsNull(Me.Consignment_Note_Number) Or IsNull(Me.From_Company) Or IsNull(Me.To_Company) Or IsNull(Me.Courier) Or IsNull(Me.addressed_to) Then
    t = MsgBox("A required field has not been completed !" & vbCrLf & vbCrLf & " Fields shown in red require an entry", vbOKOnly, "Required feilds are empty !")
    If IsNull(Me.Consignment_Note_Number) Then Me.Consignment_Note_Number_Label.ForeColor = 255
    If IsNull(Me.From_Company) Then Me.From_Label.ForeColor = 255
    If IsNull(Me.To_Company) Then Me.Label47.ForeColor = 255
    If IsNull(Me.Courier) Then Me.Label22.ForeColor = 255
    If IsNull(Me.addressed_to) Then Me.Label45.ForeColor = 255
    Exit Sub
    Else
    Me.Consignment_Note_Number_Label.ForeColor = 16777215
    Me.From_Label.ForeColor = 16777215
    Me.Label47.ForeColor = 16777215
    Me.Label22.ForeColor = 16777215
    Me.Label45.ForeColor = 16777215
    End If

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Is this in a Continuous or Datasheet view form? Won't work for either because changing a control's property changes it for every record.

    If labels and textboxes have similar names, like lblText1, lblText2, lblText3, lblText4 and tbxData1, tbxData2, tbxData3, tbxData4 - then a looping structure could be used.

    For i = 1 to 4
    If IsNull(Me("tbxData" & i)) Then Me("lblText" & i).ForeColor = 255
    Next

    An alternative is to use Conditional Formatting for the textbox and change colors of textbox.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    trevor40's Avatar
    trevor40 is offline Advanced db Manager
    Windows XP Access 2003
    Join Date
    Feb 2014
    Location
    Australia
    Posts
    402
    this fixed it...

    If IsNull(Me.Consignment_Note_Number) Or IsNull(Me.From_Company) Or IsNull(Me.To_Company) Or IsNull(Me.Courier) Or IsNull(Me.addressed_to) Then

    t = MsgBox("A required field has not been completed !" & vbCrLf & vbCrLf & " Fields shown in red require an entry", vbOKOnly, "Required feilds are empty !")

    If IsNull(Me.Consignment_Note_Number) Then Me.Consignment_Note_Number_Label.ForeColor = 255
    If IsNull(Me.From_Company) Then Me.From_Label.ForeColor = 255
    If IsNull(Me.To_Company) Then Me.Label47.ForeColor = 255
    If IsNull(Me.Courier) Then Me.Label22.ForeColor = 255
    If IsNull(Me.addressed_to) Then Me.Label45.ForeColor = 255
    Exit Sub
    Else

  5. #5
    data808 is offline Noob
    Windows XP Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    727
    Does this go into the "Before Update" property?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-28-2013, 04:10 PM
  2. Replies: 7
    Last Post: 10-28-2012, 02:55 PM
  3. how change Text field to Check box.
    By qazi in forum Queries
    Replies: 3
    Last Post: 10-01-2012, 04:41 AM
  4. Text/Combo boxes and Check box PLEASE help!!!!
    By PAS123 in forum Programming
    Replies: 4
    Last Post: 12-15-2011, 01:17 PM
  5. Replies: 1
    Last Post: 03-29-2009, 08:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums