473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Runtime Error 3075 on search button

I am trying to create a search form in Access where in people can search records by date range. But each time I click search I get a run time error 3075... with DoCmd.ApplyFilter task highlighted. I am new to VBA.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command62_Click()
  2.     ' Search Button
  3.     Call Search
  4. End Sub
  5. Sub Search()
  6.  
  7.     Dim strCriteria, task As String
  8.  
  9.     Me.Refresh
  10.     If IsNull(Me.txtDateIntakeAssignedFrom) Or IsNull(Me.txtDateIntakeAssignedTo) Then
  11.         MsgBox "Please enter the date range", vbInformation, "Date Range Required"
  12.         Me.txtDateIntakeAssignedFrom.SetFocus
  13.     Else
  14.         strCriteria = "([Date_Staff_Assigned]) >= #" & Me.txtDateIntakeAssignedFrom & "# And [Date_Staff_Assigned] <= #" & Me.txtDateIntakeAssignedTo & "#)"
  15.         task = "select * from frmCustomizeSearchDataonDatasheet where (" & strCriteria & ") order by [Date_Staff_Assigned]"
  16.         DoCmd.ApplyFilter task
  17.     End If
  18.  
  19. End Sub
Apr 10 '18 #1
1 1645
twinnyfo
3,653 Expert Mod 2GB
kmarkenday,

Welcome to Bytes!

As a newcomer, I remind you to enclose your code in code tags (use the [CODE/] button in your text editor), as this is a requirement of this forum. I have edited your post to reflect such changes.

There are a few things I find unorthodox about your code. You said you are new to VBA, so I will try to be as instructional as possible.

First, You may want to change the name of your Search Sub, as the word "Search" is one of those words in Access that can cause the DB engine to occasionally become confused. This can occur with field names like "Name" or Tables named "Table", etc.

Second, unless you are calling the Search Sub from other areas in your code, you can roll all your code under the Command Button's OnClick event. There is nothing wrong with how you have done it, especially if you call this search from multiple locations.

Third, a Filter is defined as "the WHERE clause of a SQL string, without the word WHERE." So, by assigning an actuall SQL string to the Filter, you are causing the error in the syntax of te Filter. Your line #14 should be the appropriate filter that you use.

Fourth, I am going to assume that you want this filter to filter the records that are currently being displayed onthe Form? I must assume this as it is not directly stated. Although you can use the ApplyFilter method, the more trasditional method to use is to simply directly apply the filter to the form itself. In fact, when you use the ApplyFilter method, you are setting the filter, but indirectly.

I would also highly suggest that you get into the habit of including Error Handling Code into all your procedures. Again, I have done a simple error handling code for you.

So, using the majority of your code, we would get this:


Expand|Select|Wrap|Line Numbers
  1. Private Sub Command62_Click()
  2. On Error GoTo EH
  3.     Dim strCriteria As String
  4.  
  5.     Me.Refresh
  6.     If IsNull(Me.txtDateIntakeAssignedFrom) Or _
  7.         IsNull(Me.txtDateIntakeAssignedTo) Then
  8.         MsgBox "Please enter the date range", _
  9.             vbInformation, "Date Range Required"
  10.         Me.txtDateIntakeAssignedFrom.SetFocus
  11.     Else
  12.         strCriteria = "([Date_Staff_Assigned]) >= #" & _
  13.             Me.txtDateIntakeAssignedFrom & _
  14.             "# And [Date_Staff_Assigned] <= #" & _
  15.             Me.txtDateIntakeAssignedTo & "#)"
  16.         Me.Filter = strCriteria
  17.         Me.FilterOn = True
  18.     End If
  19.     Exit Sub
  20. EH:
  21.     MsgBox "There was an error searching the form!  " & _
  22.         vbCrLf & vbCrLf & Err.Number & _
  23.         vbCrLf & vbCrLf & Err.Description & vbCrLf & vbCrLf & _
  24.         "Please contact your Database Administrator.", _
  25.         vbCritical, "WARNING!"
  26.     Exit Sub
  27. End Sub
Hope this hepps!
Apr 10 '18 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: JMCN | last post by:
I have an ftp program that i inherited and i tried to modify it to ftp over my file however, i receive an error message : run-time error '3075 syntax error (missing operator) in query expression...
3
by: william | last post by:
Hello Everyone, I'm using Access 2000. I entered the following code to do some data validation, however it is not working. I'm trying to ensure that the user cannot enter a duplicate inspection...
0
by: j.rogel | last post by:
Hello everyone! I am new to this sort of postings so I'm not even sure if this is the correct place to start. Anyway, I would realy appreciate any help. I have a some VBA code that works quite...
8
Dököll
by: Dököll | last post by:
Hey gang! Below code allows me to search my database though all fields included on the form. Works great. Small issue, when I fetch partial phrases, if they contain an apostrophy, say, "Ferris...
5
by: MARTINQC | last post by:
"SELECT ., .Category INTO tblSiteGroupActiveTicketRawData FROM .Base = 'AAAA') OR (.Base = 'BBBB')) AND (.Status != 'Closed');" Above SQL string fails with a runtime error 3075 syntax error...
1
by: BinduKatoch | last post by:
One of the entries in my database has "apostrophe" I have a form in access... When i try to select that entry from the table it gives me error "syntax error(missing expression) in query...
1
by: kickergirl | last post by:
I recently created a database in Access 2000 that has been distributed to multiple people using various versions of Access. Each person is using it as a standalone database. The database has...
3
by: adigga1 | last post by:
Hello Experts, I'm about to go grey with this dlookup statement: I'm trying to run a dlookup statement, I have the correct expression string, etc. but when I run it under the Immediate window...
3
by: timber910 | last post by:
Hello All, I'm in need of help here. I have build my query in a query builder in access as a select query. Query runs fine. Changed it to a make table query. Query makes table ok. Copy and pasted...
5
by: Vasago | last post by:
I've been having issues with my dlookup. Could someone take a look at this one and let me know where I'm going wrong. tasksE = Nz(DCount("", "Tasks", "To='" & Forms!! & " and Complete=0"), 0)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.