Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error 2107 The value you entered doesn't meet the validation rule defined for the field or control

Posted on 2014-03-01
3
Medium Priority
?
550 Views
Last Modified: 2014-04-05
I am using the following code in a search form to create an sql to use as the recordsource for the form. It works fine except for when a Date To is selected.


Public Sub SearchForm()
	'Main body of the query
    strSQL = "SELECT Distinct tblDocs.* FROM tblDocs INNER JOIN tblDocumentContents ON tblDocs.fldDocID=tblDocumentContents.fldDocID"
    
	'Create Where conditions based on the selected search controls
    strWhere = " WHERE tblDocs.fldDocID In (Select fldDocID From tblDocs "
    strWhere = strWhere & "WHERE fldDocNameID Like " & Nz(Me.cboSearchDocuments, " '*' ") & ") "
    
    If Not IsNull(Me.cboSearchPeople) Then
    
        strWhere = strWhere & "AND tblDocs.fldDocID "
        strWhere = strWhere & "In (Select fldDocID From tblDocumentContents WHERE fldEntityID Like " & Me.cboSearchPeople & ")"
  
    End If
    
   If Not IsNull(Me.cboSearchPlaces) Then
      
    strWhere = strWhere & " AND tblDocs.fldDocID "
    strWhere = strWhere & "In (Select fldDocID From tblDocumentContents WHERE fldPlaceID Like " & Me.cboSearchPlaces & ")"
   
   End If
   
   If Not IsNull(Me.cboSearchTopics) Then
      
    strWhere = strWhere & " AND tblDocs.fldDocID "
    strWhere = strWhere & "In (Select fldDocID From tblDocumentContents WHERE fldTopicID Like " & Me.cboSearchTopics & ")"
   
   End If
   
   If Not IsNull(Me.txtDateFrom) Then
   
   strWhere = strWhere & " AND tblDocs.fldDocID "
    strWhere = strWhere & "In (Select fldDocID From tblDocs WHERE fldDate >= #" & Me.txtDateFrom & "#)"
   
   End If
   
   If Not IsNull(Me.txtDateTo) Then
   
   strWhere = strWhere & " AND tblDocs.fldDocID "
    strWhere = strWhere & "In (Select fldDocID From tblDocs WHERE fldDate <= #" & Me.txtDateTo & "#)"
   
   End If
   
   'Complete the SQL
   strSQL = strSQL & " " & strWhere
    
	'Assign strSQL to the form recordsource.
    Me.RecordSource = strSQL
    
	'Refresh form if there is no records 
    If Me.RecordsetClone.RecordCount = 0 Then
    
    MsgBox "This search produce 0 records"

    Call cmdRefresh_Click
    
    End If
End Sub

Open in new window



It seems that the problem is with the codes between line 37 and 42. But the codes in these lines are almost identical to the codes in line 30-35 which works fine.
0
Comment
Question by:Sheils
  • 2
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 39898155
to see the SQL statement that was created,

   'Complete the SQL
   strSQL = strSQL & " " & strWhere

   
'Add this line

  Debug.print strSQL


look at what was printed in the Immediate window and you will see that the SQL statement is not correct, when you have both the "txtDateFrom" and "txtDateTo" (are not null) filled out.
0
 
LVL 16

Author Comment

by:Sheils
ID: 39898165
I have already tried this and even pasted the sql in a query. The query run no problem but still can't open the form. The debug print result is as follows:

SELECT Distinct tblDocs.* FROM
 tblDocs INNER JOIN tblDocumentContents ON tblDocs.fldDocID=tblDocumentContents.fldDocID  WHERE
tblDocs.fldDocID In (Select fldDocID From tblDocs WHERE fldDocNameID Like  '*' )  AND
 tblDocs.fldDocID In (Select fldDocID From tblDocs WHERE fldDate <= #02/03/2014#)
0
 
LVL 16

Author Comment

by:Sheils
ID: 39898199
OK I think that have seen the problem. I was using the before update event instead of after update by mistake.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question