Filtering subform by date field - vba

Still a new learner here so please excuse my formatting.
1. I'm trying to figure out how to filter my subform[frmSelectorquerysub] based on a date range on my parent form[Results Form].
I know it can be done in VBA, that doesn't mean I know how to do it, but I want to try to use master/child fields. I've used master/child fields to filter my subform by combobox selections and I've even got it to do three filters at once off of them.
Is it possible to use this method to filter date?
I've included my (compacted/repaired) db for an example.
Please excuse the messiness.
https://drive.google.com/open?id=0B7Uh_goO6l7QSmdPLXVqQlpiQVE
2. If it's not possible to use this method I would use BETWEEN for the range, right? How about the others where they are just single values?
3. If we can get this to work this way, would someone also be able to help me fix my syntax on my master/child fields so I don't have to set all three filters that they have right now to get results?

MasterLinkFields and ChildLinkFields are for one or more fields only.
But you can set a filter on the subform:
Dim Filter As String
Filter = "[DateFieldInSubform] Between #" & Format(Me!StartDate.Value, "yyyy\/mm\/dd") & "# And #" & Format(Me!EndDate.Value, "yyyy\/mm\/dd") & "#"
Me!NameOfSubformControl.Form.Filter = Filter
Me!NameOfSubformControl.Form.FilterOn = True

Related

DLookup returning True for some values, and False for others

I am writing a program, and I need to be able to check whether a certain 'tag' exists, by looking at all the 'tags' in the column 'CowTagMain' of the 'CowTable' table.
The code I am using is,
DLookup("[CowTagMain]", "[CowTable]", "[CowTagMain]") = Tag ...
Where tag is a String, TagMain is the column, and MainTable, is the table I am fetching data from.
I am getting inconsistent results, when I try this with 18C, it returns true. While if I try this with 18, it returns false.
I would assume I am fundamentally misunderstanding how to use DLookup, but after searching the internet for hours I cannot understand what I am doing wrong.
Even just pointing me in the right direction would be very appreciated! I am new to working with Access and VBA.
The search criteria is not within the function WHERE CONDITION argument.
The field is text type so need apostrophe delimiters.
Consider:
If IsNull(DLookup("[CowTagMain]", "[CowTable]", "[CowTagMain]= '" & Tag & "'")) Then

Multiple Criteria using autofilter on the same range, autofilter only takes last Criteria Used

I'm trying to filter multiple filters based on user input from a listbox on the same range.
However, for some reason the autosort method only sort the target range using the last criteria from testing.
I have searched everywhere, tested out array solutions (reading list info into an array), writing a range of values for filters on worksheets, changing variable type/operator to no avail. Nothing works.
Thanks for your time for reading this, would appreciate it if someone could help me with this.
dim lifecycle as range
dim List2String as string
Set lifeCycle = defineColRange(startWs, "Lifecycle Comments (Saks)", True, False)
For i = 0 To ListBox2_Lifecomments.ListCount - 1
'looping though the listbox2 to retrieve values
List2String = ListBox2_Lifecomments.List(i)
startWs.UsedRange.AutoFilter Field:=lifeCycle.Column, Criteria1:="<>" & List2String
Next i
startWs.UsedRange.SpecialCells(xlCellTypeVisible).Interior.Color = rgbLightPink 'testing to see if filter works
After some more digging, and rethinking, essentially I was asking the wrong questions.
The problem statement should be: "How to filter a range NOT equal to multiple criterias?"
It is documented here: Explaination of why .autosort doesn't work with not equal to with multiple criterias.
Few Solutions were discussed:
Use another a column to help you determine the result you want to achieve. In my example, it would be looping through all values from
user input, and output true/false on another column based on
comparison, then filter that helper column to work around this
problem.
Filter with an impossible values, this is situational. For example, if you want to filter numbers, set up an outofbound criteria for
non-numbers like given in the explanation link above.
Write code to hide the already filtered criteria, and keep filtering what is left with rest of criteria, 2 at a time.
Use advanced filters
Hope this helps others who might get into same problems in the future.

Alternative or Suggestions for DoCmd.ApplyFilter?

I have a form that is bound to the main table in my access database. There are 5 comboboxes which shows the description of the IDs that are stored in the main database.
TruckModelID is stored in the tblTruckList and relates to the TruckModelID in tblTruckModel. TruckModelName is stored in tblTruckModel.
I can make a simple search function where I can enter the ID but the user will not know the ID for specific models. How do I make some kind of search that can look at the value in txtFindTruck (my search field) and compare it to the name and then pick the correct ID and return the records from TruckList with the correct ID?
This is what I have been using when looking at values in tblMain:
DoCmd.ApplyFilter "", "[TruckID] Like ""*"" & Forms![Ändra Truck]!txtFindTruck & ""*"""
This is basically what I want:
DoCmd.ApplyFilter "", "[cmbTruckModelName] Like ""*"" & Forms![Ändra Truck]!txtFindTruck & ""*"""
However the actual value that the form uses is the TruckModelID not the TruckModelName
I am sure I have missed something in the description that makes it hard to understand, please do not hesitate to ask me anything :D also any help will be much appreciated.
You can use the SQL IN clause to filter by a different query, like this:
DoCmd.ApplyFilter "", "[TruckID] IN(" & _
"SELECT TruckID From MyTable WHERE TruckModelName LIKE ""*"" & Forms![Ändra Truck]!txtFindTruck & ""*"")"
Fill in the blanks like your table name and it should work.
However, this might not be the best solution to your problem. If you are using a combo box, you can use a hidden ID column to do the searching, and include the actual model names in the combo box, which might be more user friendly.
See How to hide columns in a ComboBox dropdown? on how to hide columns.

how can I disable rows in my gridview with datasource rowfilter?

How can I hide rows in my Gridview with a specific value? For example I want to hide all rows with column("dubletten_Vorschlaege") is empty
skmTabelle.SLXADRIUMDEVDataSet.Tables("SKM2").DefaultView.RowFilter = "Dubletten_Vorschlaege =Nothing"
said he cant find the column nothing?
skmTabelle.SLXADRIUMDEVDataSet.Tables("SKM2").DefaultView.RowFilter = "Dubletten_Vorschlaege ="""
said he cannot read the statement at """
I've never used rowfilter so I hope someone can explain.
Edit:
thx levi, it doesn't throw an exception now. But the gridview doesn't change. how do I do that? Do I need to use the fill query again?
on the formload event I have
Me.SKM2TableAdapter.Fillg(Me.SLXADRIUMDEVDataSet.SKM2, Module1.pkey)
which only selects the rows which are new.
for example I imported new 2000 rows it only shows them.
Do I need to use this statement again?
I would refer you to this site for a few tips on using rowfilter.
http://www.csharp-examples.net/dataview-rowfilter/
In your case, I think the proper way may be to write the string like this. I have followed a similar approach and this worked.
...DefaultView.RowFilter = "Dubletten_Vorschlaege ='" & "'"
you will notice that i add a single quote after the = and again add a single quote within double quotes after the &.
Also, I refer you to this StackOverflow link
How do I check for blank in DataView.RowFilter
The user simply added the line of code as this:
...DefaultView.RowFilter = "Dubletten_Vorschlaege = ''"
notice the two single qoutes before the ending double quote.

concatenation of two measures in mdx query result

is it possible to concatenate two measures values into one cell ?
this is the sample query but it doesnt work:
WITH member [Measures].[tmp] as ([Measures].[m1] + " " + [Measures].[m2])
SELECT {[Brand].[Brand Name].[Brand Name]} ON ROWS, {[Measures].[tmp]} ON COLUMNS FROM [DEVEL]
thank You very much for any help
Perhaps you need to make it clear you are after the .Value of the member, otherwise the MDX parser thinks you mean the member (object) itself?
WITH MEMBER [Measures].[tmp] AS '[Measures].[m1].Value & " " & [Measures].[m2].Value'
I've also tweaked the syntax a bit: I think you need & to concatenate (like VBA, which MDX understands if using MS OLAP), and you should need single quotes around the definition after the AS.
Alternatively, if you are using your own code to call MDX, then you can read the cell values yourself, and concatenate anything you want before displaying it?