473,666 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Runtime Error 3075 on search button

1 New Member
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.ApplyFilt er 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 1654
twinnyfo
3,653 Recognized Expert Moderator Specialist
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
4586
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 " Get PROD6-12-22-03-299-2 c:temp\'PROD6FTCERT.txt 0 As Expr1;'. i'm clueless why i have a missing operator? if anyone has a suggestions that would be greatly appreciated :)
3
1243
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 date for the same room. I'm getting the following error message: Runtime error 3075. Syntax error (missing operator) in query expression '(Room = 189B) AND (InspectionDate = #10/05/05#)'. Here is the code:
0
1833
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 happily in a number of machines and for different users. Recently we had to open a new account for a user in one of the machines and when the code runs it shows a run-time error '3075'. Nonetheless if I switch users in the same machine and run the...
8
2552
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 Bueller's Day Off", Access does not understand it an gives me either ther 3075 error, or the other. What are your thoughts on that? Any information you have is appreciated.
5
3474
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 (operator missing). I cannot figure this one out. Any assistance would be appreciated.
1
2339
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 expression." I tried using double quotes in my query. It displays the entry i am looking for but it messes up the changes i made in delete code. Can anyone help plz....
1
2612
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 multiple forms that collect information on individual people. In fact there are 5 forms per person. The first and second form write data to the same table. The VBA code below is what happens when the user continues to the second form to enter more...
3
11246
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 for testing I'm getting the runtime error. Scanerio: I'm calling an associated Price value (Currency) for a Code (text) from a Query in order to have an auto population in the fields; here is the code:
3
4653
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 the SQL into my VBA on a form and bam! Run Time error 3075. I've checked and re-checked but I'm not any closer to finguring out where i'm off. If someone could help I would be so grateful! My full code is below. My error message states "Invalid use...
5
1635
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
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8783
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.