Basically what I am looking for is a way to set the criteria of a specific field in a query from VBA.
The reason why:
I have one very large query that includes lots of fields from many tables. I want to make a "search form" that sets one or multiple fields to have criteria to narrow it down.
You could select the field, say, serial number, from a drop down on the form, then enter a serial number and click a button that would refresh the form, showing the new query output.
Then you change from "serial number" to "location" in the dropdown, and type in a location, and it would remove the criteria from the serial number field and add one to the location field. When you click the button it will refresh and show the new query output (all the items in the specified location).
Basically I am trying to create one form to search the output of a query in multiple ways. I would like to keep it to one form and not have to make multiple versions of the query with different criteria.
I found some code that lets me Filter a Report from a Popup Form. It uses 6 combo boxes with each box filtering my VehicleRecords table to the record I am looking for. The code for this can be found here: http://support.microsoft.com/kb/q208529 I modified just a few lines so that it would point to my VehicleRecords table.
When I enter information into any one of the combo boxes I get a Run Time Error 13 - Type Mismatch, and then I am pointed to this section of code.
I am using a combo box to filter a 2nd form upon clicking a button. I posted on this topic the other month and was given some code that works. I am attempting to tweak it for another part of my database.I am receiving a Run-time error "3464': Data type mismatch in criteria expression.
I have a form that has numerous fields, there is one field that is called the "Relationship Code" it gives any customers who have a certain relationship a 3 digit number. I would like a command button that you can press that will take the current record shown and filter their relationship code, to only show those records who have the same code. I know this can be done by going to the field>right clicking>and saying Equals " ". But I want a button with code that will do this automatically.
Code: SELECT Sum(Tab1.Inputs) AS SumOfInputs, Sum(Tab1.ValInp) AS SumOfValInp, Sum(Tab1.Outputs) AS SumOfOutputs, Sum(Tab1.ValOut) AS SumOfValOut, Products.Product, Products.VAT, Products.UM FROM Tab1 INNER JOIN Produse ON Tab1.ProductID = Products.ProductID GROUP BY Products.Product, Products.VAT, Product.UM, Tab1.ProductID;
Second query :
Code: SELECT Nz([SumOfInputs],0)-Nz([SumOfOutputs],0) AS Stoc, Nz([SumOfValInp],0)-Nz([SumOfValOut],0) AS ValStoc, IIf([Stoc]=0,0,([ValStoc]/[Stoc])) AS CMP, [Sum Products].Product, [Sum Products].SumOfInputs, [Sum Products].SumOfOutputs, [Sum Products].SumOfValInp, [Sum Products].SumOfValOut, [Sum Products].VAT, [Sum Products].UM FROM [Sum Products] GROUP BY [Sum Products].Product, [Sum Products].SumOfInputs, [Sum Products].SumOfOutputs, [Sum Products].SumOfValInp, [Sum Products].SumOfValOut, [Sum Products].VAT, [Sum Products].UM HAVING (((Nz([SumOfInputs],0)-Nz([SumOfOutputs],0))>0.09 Or (Nz([SumOfInputs],0)-Nz([SumOfOutputs],0))<-0.09));
I need to combine those two query sql code to make only one query.
SELECT Contacts.*,Contacts.Address1 FROM Contacts WHERE (((Contacts.Address1) like "*" * (Enter 1st Line of Address here) & "*") AND ((Contacts.Site) = "Miscellaneous")) ORDER BY Contacts.Site;
I want to replace the data "Miscellaneous" with a Public variable strSite.
If you can help I would be very happy and of course grateful.
I have been asked to help with a database that someone is writing.
He has a Table that has 200+ columns and approximately 70 of those columns are Qualifications. The first few columns are Title, Forename, Surname.
What he is trying to do is query the table to find all people with a specific Qualification and that is a Mr.
If I had written the db from the start then I would not have produced so many columns for qualifications. Instead I would have 1 column for quals and the populate each record in this way.
My question to the forum is the following:
With the current structure of his table (200+ Columns) Is there a way that I can produce a Query that will find the results that he requires, 1 specific Qualification and Title, but without displaying all other details in the table?
I understand that I can choose what field to include in the query but what I really do not with to do, is produce 70 different queries in order to filter each qualification.
Any and all help with this question really is appreciated.
I'm trying to hash two scripts I've found into 1 functioning filter, however I'm still relatively new to vba and can't figure out how to get this working.
I'm trying to use Allen Browne's Search Criteria:
with another snippete of code I found here:
Code: 'Purpose: This module illustrates how to create a search form, _ where the user can enter as many or few criteria as they wish, _ and results are shown one per line.
[Code]....
It's the date part I'm having trouble with, the rest of the search criteria work fine without the date, but I can't get it working when I try to modify and merge the date sections of each code.
Also I'm using a listbox for the "Yesterday";"Last 4 days";"Last 9 days" and not a combo box.
I have a continuous form based on table "INCOMES" that shows all the payments received, which mediums can be (field "PMNT_MEDIUM"):
- check - transfer - taxes - cash
Table "INCOMES" is filled using another form, but in this particular form I just want to show "check", "transfer" and "cash" (not "taxes") so that I can track all the cash incomes.
Note: taxes are loaded because they appear in my invoices and I need them there to reach the invoice total amount.So my form has a search bar which allows me to search by PMNT_MEDIUM listing all "checks", all "cash" or all "transfer". I can also search by payment number (meaning: check number). To that end I have a "search" button that applies the filter. And I have another button that "cleans" the filtering by "putting a "" in the search-bar and then calling the "on click" of the search button".
What I need is, no matter if I click over the "search" or "clean" button, it NEVER shows me the "taxes".Search button, on click code:
If IsNumeric(Me.busq_chq_med) Then Me.Filter = "[PMNT_MEDIUM_NUMB] =" & Me.SEARCH_BAR Else Me.Filter = "[PMNT_MEDIUM] like'" & Me.SEARCH_BAR & "*'" Me.Filter = "[PMNT_MEDIUM] like'" & Me.SEARCH_BAR & "*' or [INVOICE] like'" & Me.SEARCH_BAR & "*'" End If Me.FilterOn = True
I have a form that I use a filter on to make my where statement for the query I have. The form has 3 drop downs: County, City, and State. Everything works great except when you only choose a state you should get the totals for just the state and instead you get a report by city. Here is my sql:
SELECT Sum(IIf([Homeless]="yes",1,0)) AS HomelessCnt, Sum(IIf([NFresident]="yes",1,0)) AS NFresidentCnt, Sum(IIf([Self]="yes",1,0)) AS SelfCnt, Sum(IIf([StaffBoard]="yes",1,0)) AS StaffBoardCnt, Sum(IIf([FamilyFriend]="yes",1,0)) AS FamilyFriendCnt, Sum(IIf([CommLarge]="yes",1,0)) AS CommLargeCnt, Sum(IIf([ServeProvide]="yes",1,0)) AS ServeProvideCnt, Sum(IIf([Physical]="yes",1,0)) AS PhysicalCnt, Sum(IIf([MentalEmo]="yes",1,0)) AS MentalEmoCnt, Sum(IIf([Cognitive]="yes",1,0)) AS CognitiveCnt, Sum(IIf([Vision]="yes",1,0)) AS VisionCnt, Sum(IIf([Hearing]="yes",1,0)) AS HearingCnt, Sum(IIf([Multiple]="yes",1,0)) AS MultipleCnt, Sum(IIf([AdvocacyServe]="yes",1,0)) AS AdvocacyServeCnt, Sum(IIf([AssistDevServe]="yes",1,0)) AS AssistDevServeCnt, Sum(IIf([ChildServe]="yes",1,0)) AS ChildServeCnt, Sum(IIf([CommServ]="yes",1,0)) AS CommServCnt, Sum(IIf([FamilyServe]="yes",1,0)) AS FamilyServeCnt, Sum(IIf([HousingServe]="yes",1,0)) AS HousingServeCnt, Sum(IIf([ILSkillServe]="yes",1,0)) AS ILSkillServeCnt, Sum(IIf([InformationServe]="yes",1,0)) AS InformationServeCnt, Sum(IIf([MentalRest]="yes",1,0)) AS MentalRestCnt, Sum(IIf([MobilityServe]="yes",1,0)) AS MobilityServeCnt, Sum(IIf([PeerServe]="yes",1,0)) AS PeerServeCnt, Sum(IIf([PersonalServe]="yes",1,0)) AS PersonalServeCnt, Sum(IIf([PhysicalRest]="yes",1,0)) AS PhysicalRestCnt, Sum(IIf([PreventiveServe]="yes",1,0)) AS PreventiveServeCnt, Sum(IIf([Prostheses]="yes",1,0)) AS ProsthesesCnt, Sum(IIf([RecServe]="yes",1,0)) AS RecServeCnt, Sum(IIf([RehabTech]="yes",1,0)) AS RehabTechCnt, Sum(IIf([CounselServe]="yes",1,0)) AS CounselServeCnt, Sum(IIf([Therapeutic]="yes",1,0)) AS TherapeuticCnt, Sum(IIf([TransportServe]="yes",1,0)) AS TransportServeCnt, Sum(IIf([YouthServe]="yes",1,0)) AS YouthServeCnt, Sum(IIf([VocationServe]="yes",1,0)) AS VocationServeCnt, Sum(IIf([OtherServe]="yes",1,0)) AS OtherServeCnt, Sum(IIf([Newsletter]="yes",1,0)) AS NewsletterCnt, Sum(IIf([EventFlyer]="yes",1,0)) AS EventFlyerCnt, Sum(IIf([VFIBrochure]="yes",1,0)) AS VFIBrochureCnt, Sum(IIf([WaiverInfo]="yes",1,0)) AS WaiverInfoCnt, Sum(IIf([Survey]="yes",1,0)) AS SurveyCnt, Sum(IIf([Other]="yes",1,0)) AS OtherCnt, Sum(IIf([Advocacy]="yes",1,0)) AS AdvocacyCnt, Sum(IIf([SkillTraining]="yes",1,0)) AS SkillTrainingCnt, Sum(IIf([PeerSupport]="yes",1,0)) AS PeerSupportCnt, Sum(IIf([Deinstitutionalization]="yes",1,0)) AS DeinstitutionalizationCnt, Sum(IIf([ReferralPAS]="yes",1,0)) AS ReferralPASCnt, Sum(IIf([ReferralVFI]="yes",1,0)) AS ReferralVFICnt, Avg(PersonalInfo.MinSpent) AS MinSpentAvg, Avg(PersonalInfo.CallerAge) AS CallerAgeAvg, PersonalInfo.CallerCounty, PersonalInfo.CallerCity, PersonalInfo.CallerState FROM PersonalInfo GROUP BY PersonalInfo.CallerCounty, PersonalInfo.CallerCity, PersonalInfo.CallerState;
I have tried to take out the group by and PersonalInfo.CallerCounty, ect. Any ideas would be greatly appreciated. Thanks
I have two seperate tables that display a part number (Tables A and B). Both tables have part numbers while Table A has a segment of the part number and Table B has the full part number (ex. (A) 2501 ; (B) PUTCO-SYSTEM-2501 ). I need table A to have the full descriptions just like table B has. Is there anyway I can link the tables and run a query to get this? Thanks.
I have asked previous questions and searched extensively on this topic and I am still without a solution.
Im trying to filter a range in a queries field. Here is the way my query is organized.
All this data deals with forecasting for my company...
Version - The current version of the forecast (represents a 2 year period techniqually) Plant - One of our cement plants CK Type - Clinker Type, main ingredant for cement
All of these are for place keeping, it is the way they need to be inputed into another tool.
Layout: Version / Plant / CK Type / *Version (current) / *Version (next) / *Verison(after next) / etc.
* - Actual numbers eg 200909 for september, 2009
The other verison fields are for the actual data entry through a keystroke. They continue out to 2014 for the time being.
What I need to do is dynamically filter a range starting with the current version and ending with the version 2 years out. So I would be filtering the field.
Is this possible? Everything I have tried leads me to believe that it is not. Perhaps its in my design?
I know a formula that will get me the proper output for the version:
Version = 200711,200712,200801, etc.
iif(Version(right,2)=12,Version+89,Version+1) , but I cannot get this to populate the fields.
I have a query which lists data for 86 different units. I need to get the query to return the last entry for each position on each unit, based on turn date. There should be 16 positions for each unit. Then I need to be able to create a report based on the query for just one unit or for all 86 units. I have attached a zip file of how far I have got. I've been stuck on this for ages, so I'm hoping someone can help!
I have three fields on the form. First one is Combo box - "Contact person", Second - "Code" is Text field, Third - "Department" is the text field. Corresponding to this I have a table "Department "with fields Contact person, Code, Department.
I want that when I select the Name from the combo box, corresponding records like Code and Department should appear in the respective text box.
I have three fields on the form. First one is Combo box - "Contact person", Second - "Code" is Text field, Third - "Department" is the text field. Corresponding to this I have a table "Department "with fields Contact person, Code, Department.
I want that when I select the Name from the combo box, corresponding records like Code and Department should appear in the respective text box.
I am using the two lines of code below Each in separate columns of a query (or two text Boxes on a form) to calculate the elapsed time between two dates formatted as General Dates. The first line of code (in column A, "txtTime1") calculates to the total minutes between the two dates, the second line of code (in column B, "txtTime2") takes the minutes and converts them to total elapsed hours and minutes. They work great, however, I would like to combine this code and place it in only one query column or form Text Box. My VBA is not up to it, can someone out there show me how to combine the code below to produce the hours and minutes in one line of code? Thanks
=DateDiff("n",[StartDate],[CompleteDate])
=[txtTime1]60 & Format([txtTime1] Mod 60,":00") :confused:
I have three fields on the form. First one is Combo box - "Contact person", Second - "Code" is Text field, Third - "Department" is the text field. Corresponding to this I have a table "Department "with fields Contact person, Code, Department.
I want that when I select the Name from the combo box, corresponding records like Code and Department should appear in the respective text box.
Which should be pulling the value in cb1 in the last cat query, but im getting an error saying it cant find the field "|" refered too...
Basically there is a table called Last Cat, and I want to draw the value of cb1 out of it where the catpathid = 5 so i made the query to do that... but now im abit lost....
Im looking to have a query that selects the "NAME" from a table "tblPeople" where the NAME field begins with "A". Ive tried using WHERE tblPeople.NAME Like "A" with no luck.
Can anyone help me out, im sure im missing something really simple.
I need to display the results of a query on screen when somebody clicks a button on the form. So I put code in the event of the click that looks like this:
Private Sub Command20_Click() On Error GoTo Err_Command20_Click
So far, so good, but my problem is that this query is one row with a lot of columns - that creates a lot of pages to look through. Is there a command that would loop it around on the same page, or rotate it clockwise so it's going down the page instead of across?
I am having trouble with some code I am using on a query. Part of the query comes from two fields in a form. The rest comes from a table. The query then populates a report. The code I have written works fine. The trouble starts when I try and enter in some code so that if some of the fields in the form is left blank, it just returns values based on the fileds that has data, so ignores any blank fields. I have tried to use examples illustrated in this Forum, but it does not seem to like it. I keep on getting the request to fill in the parameter value. I am sure it is something simple!
This is the code I have entered for the Invoice Date Field: Between [Forms]![Invoices]![Invoice date 1] And [Forms]![Invoices]![Invoice date 2] (this is so the user can enter a date range with the two fields)
OK I have worked in Access for awhile now but never worked with SQL statements or anything like that. This is what I am trying to do I want a criteria in a query come from a public string that I have. When some one logs in to the database it stores what property they work for I only want records to show up for that property. I don’t want them to have to type in there property code again every time the query is run. What do I need to do to get this to work? Any help would be greatly appreciated. Thanks
I have three fields on the form. First one is Combo box - "Contact person", Second - "Code" is Text field, Third - "Department" is the text field. Corresponding to this I have a table "Department "with fields Contact person, Code, Department.
I want that when I select the Name from the combo box, corresponding records like Code and Department should appear in the respective text box.