I have an Excel workbook which I use to extract data from an Access database using VBA. A requirement has popped up to show things from the last week. Unfortunately, I can't just use a Date()-7 query in Access as the start point might be different, so it needs to be based on seven days prior to a date field in Excel.
So, I have a cell in Excel with a date, in this case "16/01/2014". I want to then use that date in my query to say "greater than 8 days prior to to this date". The field is formatted as a date and the variable (DatafileDate) taken from this field and passed to the function is a Date. In my Select query I then have this line to select the top 5 marked as UK accounts in this case:
Code:
SearchText = "SELECT TOP 5 * FROM `" & TableName & "` WHERE `" & TableName & "`.`Account`='UK' AND `" AND `" & TableName & "`.`Close Date` > #" & DatafileDate & "#"
Code:
#" & DatafileDate & "#" -8
Should mention that the TableName stuff is so the name of the table can be set elsewhere. "Close Date" is the column in my Access query I need to filter on.
I want it to filter out any matches between the 7 fields. Here is my code:
Code: Private Sub Command19_Click() Dim strFilter As Variant, _ strSDate As String, _ strEDate As String 'check Text13 Text13.SetFocus 'set focus to Text13 to be checked
[code].....
It will only filter for Build Date 1 and not for any of the other fields.
I'm having a rough time trying to figure out how to pass a date to an SQL statement that Excel VBA macro will run. The date is in a cell (A1) formatted as 'm/d/yyyy'. Let's say it's 2/1/2014. I want to run an SQL statement that retrieves data from a table where a field is greater than 'A1'. The table field is a date/time field and has values formatted as 'mm/dd/yyyy'.
I've tried various syntax on the Where but cannot get it to work. sd = Range("A1") SELECT [tn].[Date Submitted] FROM[tn] WHERE tn.[Date Submitted] > """ & sd & """
This results in the following where clause that does not work. WHERE tn.[Date Submitted] > "2/1/2014"
I have an Access database with millions of records.I am only interested in a subset of records (250,000+) that I would like to analyze in an Excel pivot-table. My issue is; how do I best export this information to Excel.I've tried filtering and exporting, but all records are exported. I've tried copy and paste but only 65K are allowed. Is there a better way to do this, perhaps linking the Access database?
I have a form which i use for a user to select an excel file they want to import and then click a cmd button to import the file into a table which works fine, however i want to append a date into a date field from an unbound txtbx before the file is imported so it will look something like;
I have an excel file linked to a table in Access. Several fields are date data types in excel but are showing up as text fields in Access.
My real goal is to do a comparison between two tables, but only if the date of the one piece of data is newer than the other. I had planned on comparing the two date fields but even though I have formatted the date fields in my excel file to be "Date", when I look at the design view of my table it is showing up as "Text" and therefore I am unable to do this comparison.
I'm not sure if it's just something that I'm missing but maybe someone else knows an easy fix to this. I know this is probably a simple question, but I did search the forum and didn't find a thread that specifically dealt with this issue.
This query is to show aging. I have a field for processed date. I have a query that allows a date range to be selected using the Between function.
The query runs and pulls these variables from a form. It shows only those accounts which were processed between those dates.
However, it is also showing all of the accounts that have no date in this field. I need to set it up so that if the field has no date then it doesn't show those accounts.
I've tried Not (is null) for the criteria but that isn't working. I've tried a lot of stuff but nothing seems to work.
i have created a new form based on a database called RptSmp97 from microsoft knowledge DB. My form, as in the sample, calls a report when it is opened and at the same time shows you a multicombo form for filtering the report. In the sample the form uses only text fields, but i need to use numeric and date fields too. I could solve the problem with the numeric combos adding a condition for them, however, when i add another condition for the date it doesnt work. Also, at the end of the code i print the sql and it looks perfect.
here is the code when the apply filter button is pressed....
Private Sub Command18_Click() Dim strSQL As String Dim intCounter As Integer
'Build SQL String For intCounter = 1 To 15 If Me("Filter" & intCounter) <> "" Then MsgBox Me("Filter" & intCounter).Tag If Me("Filter" & intCounter).Tag = "effective_dt" Or Me("Filter" & intCounter).Tag = "issue_eff" Then strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " >= (" & Me("Filter" & intCounter) & ") And " End If If Me("Filter" & intCounter).Tag = "change_id" Or Me("Filter" & intCounter).Tag = "priority" Or Me("Filter" & intCounter).Tag = "Dom" Or Me("Filter" & intCounter).Tag = "Intl" Or Me("Filter" & intCounter).Tag = "Tasman" Or Me("Filter" & intCounter).Tag = "Regional" Or Me("Filter" & intCounter).Tag = "AA" Then strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & Me("Filter" & intCounter) & " And " End If If Me("Filter" & intCounter).Tag = "name" Or Me("Filter" & intCounter).Tag = "status" Or Me("Filter" & intCounter).Tag = "assignee" Or Me("Filter" & intCounter).Tag = "app_status" Then strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And " End If End If Next
If strSQL <> "" Then 'Strip Last " And " strSQL = Left(strSQL, (Len(strSQL) - 5)) 'Set the Filter property MsgBox strSQL Reports![RepFilter].Filter = strSQL Reports![RepFilter].FilterOn = True End If
i am trying to build a marine turbine and parts log and have a problem in satisfying a working rule.
i have 2 tables which i have attached,
table 1 shows the on / off dates that a generator was fitted to a turbine
table 2 shows a general date history of the generator, when it had checks done, fitted, etc
what i would like to do is fit the generator again to another turbine
using a continous form to show the available dates in table 2, i would NOT like to see the dates during the period when the generator was fitted previously as shown in the on / off the dates in table 1.
the working rule being that a generator can not be fitted to 2 different turbines at the same time
can anybody point me in the right direction or assist in how i can overcome this problem
I've created a Form where I enter all my data - then I created a Report to output this data, it includes two buttons to filter based on one category. That's working fantastically well for me.
But now I would like to filter on dates. For example, last 7 days, last 14 days etc - and also give the user the option of filtering between x and y dates. I've discovered this is easily done by right-clicking the date field in the report, but I'd prefer to embed these commands into buttons etc so it's easier to navigate.
I have a table that has a list of order information, there are multipule records per order that have information about when the order was processed. There is a day tied to the process time of each record, I need to filter out the duplicate records and get one record for an order, but that one record must be the first process time entry for that order. Anyone know how to make this query? Let me know if this doesnt make sense.
I have a database with a table of employees, and that has a column named "DaysOff", into which I type a couple of days like this: "SUNDAY AND MONDAY"
Next, I have a form onto which I will display a query of those employees. The form contains a field called DATE in which I display the mm/dd/yyyy date. What I want to do is this:
I only want those employees that have a DaysOff field that DOES NOT CONTAIN the WEEKDAY NAME of the date in the DATE field. So, for instance, if the DATE field read 2/22/2014, and I have three employees as such:
Employee 1 DaysOff "Monday and Tuesday" Employee 2 DaysOff "Friday and Saturday" Employee 3 DaysOff "Sunday and Monday"
In that case, ONLY EMPLOYEES 1 and 3 should show up. Employee 2 will NOT show up, because his DaysOff field contains the word "Saturday", and the WEEKDAY FORMATTED value of the DATE field is "Saturday"
I hope that's not too confusing. Again, this needs to be the filter criteria for the query. That query will only return a list of employees that are NOT off on the day in question. If one of their off days is the day in question, the query won't return that record.
I've tried a few things, but I can't get it to work. If you want, I can list the various things I've tried, but I imagine one of you knows exactly how to do what I need to do, and you won't need my feeble attempts as a springboard.
I am new in MS Access programming and is trying to create a search form for all records based on selected dates and check box. I was able to filter the records by dates but can't find ways to filter the records that meet the dates to be filtered again based on the selected check box/s. Basically what I wanted to is display all the records within the selected dates and check box/s.
My report generates base on 2 date inputs(from textboxes) namely, ProcStartDate & ProcEndDate & a combobox(cmbRptSupplier) to select the supplier:
Code: Private Sub btnReport_Click() Dim strDocName, strWHERECondition As String strWHERECondition = "" If Me.cmbRptSupplier = "" Or IsNull(Me.cmbRptSupplier) = True Then
[Code].....
When I leave my cmbRptSupplier blank (so that I can leave supplier out of my criteria), & fill in 1/2/2013 for ProcStartDate, 14/3/2013 for ProcEndDate, I get ALL the invoices displayed in return for my report. Even with those before 1/2/2013.
Access version: 2013 / The user can click a button on the report that opens a form where they can select various filters. Once the user has selected the filters and clicks done, I have some VB code that fires which builds an SQL string with all of the filters selected. It then reopens the report with the new filter.
What I am running into issues with is one specific filter that the user can select. They can select a "from date" and "to date". Sometimes this filter returns what I want and sometimes it doesn't.
For example. I set 01/01/14 as the start date and end date as 15/01/14. <-- this works as desired.But if I put start date as 10/12/13 and end date 15/01/14 for example then it returns all previous records up to the specified end date. I.E dates such as 10/10/13 will show.
This is the VB code used to build the SQL for this filter:
I am using this code to filter a List Box based on a Date range and a Combo Box selection:
Code: Private Sub Combo139_AfterUpdate() Dim StrgSQL As String StrgSQL = "SELECT [User Name], [Date Of Request], [Description of Problem], Status, Sub_Job FROM QRY_SearchAll " & _ "WHERE [Date of request] BETWEEN #" & CDate(Me.txtStartDate) & _ "# AND #" & CDate(Me.txtEndDate) & "#;" StrgSQL = StrgSQL & " WHERE Sub_Job = Combo139" Me.SearchResults.RowSource = StrgSQL Me.SearchResults.Requery End Sub
However, It is not working. when I click the Combo box the List Box comes up blank.
I'm having a rough time finding information regarding filtering using multiple check boxes that are not part of an option group. I have 4 "sets" of check boxes that can each have multiple selections made.
For example I have:
12 check boxes for each month 6 check boxes for a selection of years 6 check boxes for order types 5 check boxes for order company
I have written code that successfully creates a string depending on what boxes are checked that looks like this.
[Ship month] = "1" OR [Ship month] = "2" OR [Ship month] = "5" AND [Ship Year] = "2013" OR [Ship Year] = "2014" AND [OrderType] = "SO" OR [OrderType] = "SM" AND [Order Company] = "10430" OR [Order Company] = "10440"
The problem is that it does not filter correctly. After playing around with it I found that as long as the entire is using all AND operators or all OR operaters it works fine, but as soon as I mix them it doesn't work.
I am using a form in which i am filtering the results in the list box based on the textbox value. I am dynamically switching 3 row sources for the list box.
My Need is that the results produced in the listbox should get filtered again when typing in the second text box i.e based o the country name.
I am using the following code to filter my form with a search box:
Code: Me.RecordSource = "qryCompanies" Me.Filter = "CompanyName Like '*" & Me.SearchTxt & "*' Or webpage Like '*" & Me.SearchTxt & "*' Or PriorName Like '*" & Me.SearchTxt & "*'" Me.FilterOn = True
[Code] ....
It works great with one minor issue: if I try to search for a name containing an apostrophe, I get a syntax error. So, it won't find Children's Hospital for example.
But after the "Me.[Username]" part, I want it to also filter to only show me data that has null values on a column called "PN".Alternatively, I also need a code that instead of only showing me data that has null values, I want it to show me data that excludes the data with null values on the column called "PN".
I'm using 4 combo-boxes in order to filter a tabular form in access.
One combo box is for a company name the second is for a report type and the third and forth is for choosing years. I used VBA in order to apply the filter:
Each line works by itself but I cant figure out how to combine them together, or how to use "AND" between each filter so the filtering will refer all of them when I run the code.