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
511 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 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
OK I think that have seen the problem. I was using the before update event instead of after update by mistake.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now