Results 1 to 7 of 7
  1. #1
    Skroof is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2012
    Location
    South Africa
    Posts
    21

    IF statements for texts boxes

    Please help with the IF statement to check if all the boxes are filled, if not then throw "Please complete all fields" when I click on "add record button"
    here is how my code looks and the picture is attached:
    Private Sub btnSaveCommand_Click()
    Me.AppointmentDate.SetFocus
    If Me.AppointmentDate.Text = "" Then
    MsgBox "Please complete all fields"
    ElseIf Me.cboClient.Value Then
    MsgBox "Please complete all fields"
    ElseIf Me.cboSalon.Value Then
    MsgBox "Please complete all fields"
    ElseIf Me.cboSalon.Value Then
    MsgBox "Please complete all fields"
    ElseIf Me.cboStaff.Value Then
    MsgBox "Please complete all fields"
    ElseIf Me.cboService.Value Then
    MsgBox "Please complete all fields"
    ElseIf Me.ProductID.Value Then
    MsgBox "Please complete all fields"
    End If
    Else
    DoCmd.GoToRecord , , acNewRec
    MsgBox "Thanks - Appointment Booked!"



    End Sub
    Attached Thumbnails Attached Thumbnails ifstatement.JPG  

  2. #2
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    Try this

    Code:
    Private Sub btnSaveCommand_Click()
        Me.AppointmentDate.SetFocus
        If Me.AppointmentDate = "" or isnull(Me.AppointmentDate) Then
       MsgBox "Please complete all fields"
    ElseIf isnull(Me.cboClient) Then
      MsgBox "Please complete all fields"
    ElseIf isnull(Me.cboSalon) Then
       MsgBox "Please complete all fields"
    ElseIf isnull(Me.cboSalon) Then
       MsgBox "Please complete all fields"
       ElseIf isnull(Me.cboStaff) Then
       MsgBox "Please complete all fields"
       ElseIf isnull(Me.cboService) Then
       MsgBox "Please complete all fields"
       ElseIf isnull(Me.ProductID) Then
       MsgBox "Please complete all fields"
    End If
    Else
            DoCmd.GoToRecord , , acNewRec
            MsgBox "Thanks - Appointment Booked!"
        
        End Sub

  3. #3
    Skroof is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2012
    Location
    South Africa
    Posts
    21
    Hi R Badger

    It gives "Please complete all fields" , you click "ok" and then you get "Thanks - Appointment Booked!" . I think we getting there, what might be wrong now.

  4. #4
    Subwind is offline Can Only Learn
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Location
    Portsmouth, UK
    Posts
    61
    Why not have the add record button disabled until all fields have data? That way it is impossible to save the record without first entering all data.

    ~Matt

  5. #5
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    one small other typo i just saw!

    Code:
    Private Sub btnSaveCommand_Click()     
    Me.AppointmentDate.SetFocus     
    If Me.AppointmentDate = "" or isnull(Me.AppointmentDate) Then 
       MsgBox "Please complete all fields" 
    ElseIf isnull(Me.cboClient) Then   
    MsgBox "Please complete all fields" 
    ElseIf isnull(Me.cboSalon) Then 
       MsgBox "Please complete all fields" 
    ElseIf isnull(Me.cboSalon) Then    
    MsgBox "Please complete all fields"    
    ElseIf isnull(Me.cboStaff) Then    
    MsgBox "Please complete all fields"    
    ElseIf isnull(Me.cboService) Then    
    MsgBox "Please complete all fields"    
    ElseIf isnull(Me.ProductID) Then    
    MsgBox "Please complete all fields" 
    Else         
    DoCmd.GoToRecord , , acNewRec         
    MsgBox "Thanks - Appointment Booked!"    
    End If      
    End Sub
    The end if was before the else, I am a little confused why that didn't throw an error but give it a go
    Last edited by R_Badger; 05-31-2012 at 12:47 AM. Reason: forgot code tags

  6. #6
    Skroof is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2012
    Location
    South Africa
    Posts
    21
    Thanks a lot R Badger

    My problem is resolved.

  7. #7
    Skroof is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2012
    Location
    South Africa
    Posts
    21
    Oops R Badger, i have another small addition on that code. I need this line to show me the current AppointmentID it made, I have MsgBox "Thanks, Appointment Booked! Please use" & " Ref " & AppointmentID
    But it does not pop the Ref number(meaning AppointmentID)
    Private Sub btnSaveCommand_Click()
    Me.AppointmentDate.SetFocus
    If Me.AppointmentDate = "" Or IsNull(Me.AppointmentDate) Then
    MsgBox "Please complete all fields"
    ElseIf IsNull(Me.cboClient) Then
    MsgBox "Please complete all fields"
    ElseIf IsNull(Me.cboSalon) Then
    MsgBox "Please complete all fields"
    ElseIf IsNull(Me.cboSalon) Then
    MsgBox "Please complete all fields"
    ElseIf IsNull(Me.cboStaff) Then
    MsgBox "Please complete all fields"
    ElseIf IsNull(Me.cboService) Then
    MsgBox "Please complete all fields"
    ElseIf IsNull(Me.ProductID) Then
    MsgBox "Please complete all fields"
    Else
    DoCmd.GoToRecord , , acNewRec
    MsgBox "Thanks, Appointment Booked! Please use" & " Ref " & AppointmentID
    End If
    End Sub

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

Similar Threads

  1. Replies: 9
    Last Post: 06-04-2014, 10:45 AM
  2. Replies: 2
    Last Post: 12-31-2011, 02:52 PM
  3. Replies: 2
    Last Post: 11-25-2010, 11:01 AM
  4. sending texts from my pc with Access
    By bwian1234 in forum Access
    Replies: 1
    Last Post: 08-26-2010, 05:43 AM
  5. If statements
    By Ezeecopy in forum Access
    Replies: 0
    Last Post: 03-24-2009, 04:54 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