473,394 Members | 1,718 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.

Trying to open Form with a Filter in VBA

DJRhino1175
221 128KB
I'm trying to open a form that is filter by using VBA.

I have tried using the following:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub cmdRabbitsDue_Click()
  5.  
  6. DoCmd.OpenForm _
  7.     FormName:="frmRedRabbitDueInput"
  8.     WhereCondition:="[DateToRecertify] <= #" & Format(Me![DateToRecertify].Value, "mm/dd/yyyy") & "#"
  9.  
  10. End Sub
But I get a syntax error. I think I have the structure way off but not sure.

Thanks for the help in pointing me into the right direction
Aug 5 '19 #1
3 2595
DJRhino1175
221 128KB
I give a little more background info...I'm trying to open a form in datasheet format but with records containing dates that are less than the following months date...Example: all records containing a date that is less than 9/1/2019. I can get it to work if I put it in the query as < #9/1/2019# but then I need to go into the query every month to change it. So I'm trying to do it with VBA similar to the code above, but I think I'm off by a little bit. Tried to Google it and was getting everything but what I needed.

Form Name: = "frmRedRabbitDueInput"
Date Control Name is:= "DateToRecertify"
Aug 5 '19 #2
DJRhino1175
221 128KB
Found a work around. I put <CDate([Enter Date]) in the query for this date and on button click i have:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub cmdRabbitsDue_Click()
  5.  
  6. On Error GoTo Error
  7.  
  8. DoCmd.OpenForm _
  9.     FormName:="frmRedRabbitDueInput"
  10.  
  11. Error_Exit:
  12.     Exit Sub
  13.  
  14. Error:
  15.  
  16. Select Case Err.Number
  17.     Case 2501:
  18.         GoTo Cancel_Error
  19.     Case 3071:
  20.         GoTo NothingEntered_Error
  21. End Select
  22.  
  23. Cancel_Error:
  24.     Resume Next
  25.     Exit Sub
  26. NothingEntered_Error:
  27.     MsgBox "Please Enter a Date!", , "Forgot Date"
  28.     DoCmd.OpenForm _
  29.     FormName:="frmRedRabbitDueInput"
  30.     Exit Sub
  31. End Sub
  32.  
Aug 5 '19 #3
NeoPa
32,556 Expert Mod 16PB
It looks like a simple case of a missing comma (,) DJ.

Nicely formatted but you still need a comma between the parameters ;-)
Aug 22 '19 #4

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

Similar topics

1
by: Dalan | last post by:
I probably just need a simple piece of code to do this as the couple tried so far have failed. I created a new Access 97 Form Filter (frmFilterForm) which displays most of the key data fields from...
2
by: allyn44 | last post by:
Hello, I have built a serch form for users to edit records. I only want them to pull up the record they need, and I want to check for nulls. There should not be dupes becasue the underlying...
2
by: Henrootje | last post by:
Hello there! I have a piece of code in a module (function) that constructs a filter. But now I run into a problem..... It seems that I can only set a filter form a module if I open the form...
14
by: keri | last post by:
Hi, Simple version of the question..... How do I use the where clause of the open form command to show an account with a matching ID to be displayed when the form is opened? Eg. I select a...
2
by: patriciashoe | last post by:
Greeting All I have several public variables which I use to build a filter string that I would like to use when I open a form and several associated sub forms. I have set the value of the combo...
5
by: phill86 | last post by:
Hi, I have a form that I have applied a filter to by using combo boxes which works fine. Is there a way to apply that filter to the forms underlying query Here is the code that I use to...
2
by: phill86 | last post by:
Hi, I am filtering a report using the form filter with the following code DoCmd.OpenReport "report1", acViewReport, , Me.filter Which works fine untill I filter the form on one of the...
7
by: munkee | last post by:
Hi all, I am using Allen's excellent form filter script to filter the results from a query. I would now like to add some further functionality. How do I go about displaying say the top N costs...
0
by: JpjVB | last post by:
Hi, I've developed a form filter that produces a number of hours budgeted by employee/location/practice group/experience level and date available using some Allen Browne code. I have two command...
3
by: rwalle | last post by:
Hi I have a strange problem in a form filter my set up is as follows there is a form named "InAlarmResumeForm" that has a subform "AlmActiveQrySform" the form has Textboxes with datapicker enabled...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
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
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.