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
516 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
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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 …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

912 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

22 Experts available now in Live!

Get 1:1 Help Now