Results 1 to 3 of 3
  1. #1
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142

    Check if the value is present in the table or not

    Hello Everyone
    I am trying to validate a text box.
    If the value entered in the text box is in a table, it should pop up with yes/no msg box.
    1. If yes, then the current form should close or not visible and opens another form.
    2. If no, then set focus on the text box.
    If the value is not present in the table , current form closes, opens another form.


    I am not able to get the second part.
    I used the below code. Message box works fine.

    Code:
    Dim LResponse As Integer
     
    If WeekendingCmbo = DLookup("[WeekEnding]", "Timesheet_T", "WeekEnding = #" & Format(Nz(Forms!Create_New_Entry_Menu_F!WeekendingCmbo, 0), "Short Date") & "# And EmployeeID= Text34  ") Then
    LResponse = MsgBox("You have entered a timesheet on this week. Do you want to edit the existing timesheet. ", vbYesNo, "CONTINUE")
    If LResponse = vbYes Then
    Forms("Create_New_Entry_Menu_F").Visible = False
    DoCmd.OpenForm "Edit_Timesheet_Menu_F"
    Else
    Me.WeekendingCmbo.SetFocus
    
    End If
        End If
    But if the value is not present in the table. I am not able to process the steps for that.

    Code:
    Forms("Create_New_Entry_Menu_F").Visible = False
    DoCmd.OpenForm "Create_New_Entry_F"

  2. #2
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    I found a solution just after posting this.
    I used the below code:

    Code:
    Dim LResponse As Integer
     
    If WeekendingCmbo = DLookup("[WeekEnding]", "Timesheet_T", "WeekEnding = #" & Format(Nz(Forms!Create_New_Entry_Menu_F!WeekendingCmbo, 0), "Short Date") & "# And EmployeeID= Text34  ") Then
    LResponse = MsgBox("You have entered a timesheet on this week. Do you want to edit the existing timesheet. ", vbYesNo, "CONTINUE")
    If LResponse = vbYes Then
    DoCmd.Close acForm, ("Create_New_Entry_Menu_F")
    DoCmd.OpenForm "Edit_Timesheet_Menu_F"
    Else
    Me.WeekendingCmbo.SetFocus
    End If
    Else
    Forms("Create_New_Entry_Menu_F").Visible = False
        
       DoCmd.OpenForm "Create_New_Entry_F"
        End If
       
    End Sub

  3. #3
    Shamli is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Jul 2018
    Location
    California
    Posts
    142
    I am not able to delete the thread. So marking as solved.

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

Similar Threads

  1. Replies: 8
    Last Post: 08-25-2018, 10:00 AM
  2. Replies: 1
    Last Post: 05-06-2015, 04:28 AM
  3. Replies: 5
    Last Post: 05-09-2014, 02:38 PM
  4. Replies: 1
    Last Post: 09-14-2012, 10:27 AM
  5. Look if value is present
    By JeroenMioch in forum Access
    Replies: 3
    Last Post: 07-02-2012, 06:12 PM

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