Modules & VBA :: Function That Loops Through A Set Of Fields Seeking A Non Zero Value?
Apr 17, 2014
The idea is that I have a table with products. It is joined to another table that has each products ID and then a series of fields that correspond to each month of this year (so 12 fields). These fields contain how many of each product sold in that month. However some products did not appear in inventory until a few months into the year, so they have zero's for those months in which they didn't exist yet.
What I need to do is find the first month that each product went on sale, and pass that field back to my main table to do calculations with.
First I tried to do with with a query, but I ran into a road block and realized that maybe a query wasn't best as I likely needed a loop. So I started writing a function at that point... but it is obviously non functional.
Then the idea of this function would be to look at Month 1, see if it contained a zero. if it did, move to month 2. If it doesn't, then send whatever that value is to a new field in the database.
Having problem with loops. The inner loop updates a table. The outer loop pulls the record number from the "tblChangeOrderTable_Edit_Count" and is assigned to strRecordID . The inner loop uses strRecordID to find the right record. I keep getting errors like (Object variable or With Block variable not set.)
Code: Private Sub btnClose_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim db As Database, rs As Recordset, rs1 As Recordset2 Dim Criteria As String Dim strAns1 As String Dim strAns2 As String Dim strCount1 As String Dim strAns3 As String
I am running an export function from a module1 that contains a loop nested within a second loop. Each loop is running through items in a separate combobox on a single form1. The outside loop goes through combo1 items and the inner loop goes through combo2 items.
My issue is that the value of combo1 determines what items are available in combo2 (values are tied to tables). I can get the combo2 values to update when a user changes the values in combo1 (using requery in the afterupdate property of the combo1). However, I do not want a user to change the values, and the code module1 is ignoring the requery. How to force the combobox to requery through code in a module?
Last week some very altruistic folks here helped me solve a many-to-many relationships quandry, and I am hoping that there may some others out there who can help with another question.
I have a feeling this is simple, but I can't quite get my head around it, and have not been able to find it in the past forum threads, but....
I want to create a tblJobs that has information about our clients' Companies, as well as Contact. As there can be many Contacts for each Company, my current setup looks like this:
tblContacts ContactID (Pkey) Name Lookup_to_qryCompanies_to_Contact(shows Contact's company)
tblComanies CompanyID (Pkey) Company Name (Client info is included as embedded table based on qryCompanies_to_Contact)
qryCompanies_to_Contact Company (from tblCompanies) Contact (from tblContacts) (one-to-many)
In my new tblJobs, I would like to have a combo box in which I can input the company name, and then the next field will have another combo containing ONLY names of the contacts affiliated with the chosen company. (I will also eventually like to make a form that allows the same function, but am assuming that the process will be the same for updating the table trhough a form as it would be updating it directly).
I a trying to list all fields from ALL tables in a certain DB.I am using the tableinfo function. However, because the output of the immediate window is limited to 200 lines, I can only see the last 200 fields. Is there a way to export this in another way than the debug.print procedure, so I can bypass this limitation?
Code:
Public Sub showtablefields() Dim db As Database Dim tdl As TableDef
I have a table with only two fields and one record: BegDate and EndDate (beginning and end date of the reporting period respectively). I also made a function with variables that look up those values for use as a date parameter in a query.
Here is the code:
Option Compare Database Option Explicit Public Function getCurrentRepDates() As Date Dim dtBegDate As Date dtBegDate = DLookup("BegDate", "tblCurrentRepDates")
[Code] ....
I am getting a syntax error for the line marked red. How can I use "Between" function in VBA code? Access 2010
Is it possible to have sequal loops of some kinda? The basic setup of my DB is a table named "EC Faculty 2005", field name "Status", and the status field can be either "Approved" "Disapproved" and "In Process". There is another field called "Term Start Date" which holds months. I have been trying to create a SQL or some kind of query that will go through each month Jan, Feb, Mar, and so on, and count the number of Approved, disapproved, and in process for each month. This is what I have so far. Code:SELECT (SELECT Count([Status]) FROM [EC Faculty 2005] WHERE Status='Approved') AS Appr, (SELECT Count([Status]) FROM [EC Faculty 2005] WHERE Status='Disapproved') AS Disappr, (SELECT Count([Status]) FROM [EC Faculty 2005] WHERE Status='In Process') AS In Proc FROM [EC Faculty 2005]; That gives me a total count of the 3 statuses. Is there a way to loop this to count each status for each month? I hope thats not too confusing.
I am attempting to create a form for the automated printing of a series of reports. The form is tied to a query that captures Territory ID, Sales Rep ID, # of Reps in that Territory, Total # of Territories. Once completed, the code behind the form should: 1)Print the cover page report (Salesrep Sales Analysis – Cover); 2)For each of the territories, print a report for each sales rep (Salesrep Sales Analysis - A Rep) and once all the reps for that territory have been printed, print a summary report for that territory (Salesrep Sales Analysis - A Territory; 3)Print a combined report for all sales reps (Salesrep Sales Analysis - ALL by Month); and finally 4)Print the final page report (Salesrep Sales Analysis - Territory Totals).
I created the following code to accomplish that, but the results are in error: 1)The first rep for the first territory is being repeated (doesn’t seem to move off that first record at the correct time); 2)The final rep for the first territory is being skipped, and the first summary report is printed; 3)The second territory ends 1 rep short and the code moves into the 3rd territory without printing the summary for the 2nd territory; 4)The 1st rep of the 3rd territory prints, then the territory summary prints, then the 3rd territory continues, again stopping short of the final rep before moving to the 4th territory; 5)The two reps of the 4th territory (only 2 for that one) print, then the summary report for the 5th territory prints without printing the 4th territory summary or the report for the single rep for the 5th territory; 6)All three of the reps for the 6th territory print, then the summary for the 7th territory prints; 7)Three of the four reps for the 7th territory print, then I get an error message “You can’t go to the specified record” which ends the routine before the summary for that 7th territory and the last two reports are printed.
Private Sub Form_Open(Cancel As Integer) DoCmd.Maximize
' Set Variables for Rep Count, Territory Count, Page Number and Date/Time TotalReps = Me.CountOfSO_Rep RemainingReps = TotalReps Me.RepCount = RemainingReps TotalTerritories = Me.CountOfTerritory RemainingTerritories = TotalTerritories Me.TerritoryCount = RemainingTerritories PageNumber = 2 Me.PageNumber = PageNumber Me.myTime = Now()
' Turn off action/warning messages DoCmd.SetWarnings False
' Loop through all the Territories - 01, 02, 04, 05, 06, 08, 09 Do While RemainingTerritories >= 1
' Loop through all Reps for the Current Territory Do While RemainingReps >= 1 DoCmd.OpenReport "Salesrep Sales Analysis - A Rep", acViewNormal DoCmd.GoToRecord , , acNext RemainingReps = RemainingReps - 1 Me.RepCount = RemainingReps Me.PageNumber = PageNumber + 1 Me.Repaint Loop ' End of Rep Loop
' Print Territory Totals Report for the Final Territory DoCmd.OpenReport "Salesrep Sales Analysis - A Territory", acViewNormal
' Print Totals Report for All Reps Combined DoCmd.OpenReport "Salesrep Sales Analysis - ALL by Month", acViewNormal
' Print Totals by Territory Report - Final Report Page DoCmd.OpenReport "Salesrep Sales Analysis - Territory Totals", acViewNormal
' Notify User that All Reports Have Been Printed Beep MsgBox "Salesrep Sales Analysis Reports have been sent to the printer.", vbOKOnly, ""
End Sub
I’ve spent a couple of days looking at this, trying different things, and am not getting satisfactory results. Can anyone find what I’m doing wrong here? Thanks very much for any help you can provide!
I have successfully paged through a recordset on my page using the .recordCount, etc. methods, the only thing is I have 2 independent recordsets looping on the page, which when there was not paging involved this worked fine, however now I need to span the results of BOTH of these across pages, I just cannot seem to figure out how! I have one set of records paging fine, but the other either messes the page up, or shows on the first page of results and no more of the other recordset, etc.... so yeah that is basically the problem I am hitting, so I was just wondering is there any examples or ways you could tell me to do this??
Any help that can be offerered would be very much appreciated ).
Hi all, I am new here, I am never one to ask for help, but I am desperate to get some assistance and hoping someone may be able to help me. I have just basic knowledge of MS Access, but no where near the skills needed to acheive what I am needing. To explain, I am involved with a national memorial of all the Truck drivers who have been killed on our roads. I have a database in access, (near 1000 individuals and sadly growing) but wanting to create it into a form style. I also need to add a photograph of each deceased person and a second photograph of the plaque which they are on. Years ago I saw a form which I was impressed with, it looked so professional but never had the oportunity to investigate or disect it :)
I am hoping sks who will enjoy the challenge may be able to assist me.
more about the memorial can be seen at www.tarcuttamemorial.com Thanks Dianne
I read about your different topics/discussions but still have issues. The group I work for needs to track Customs entries, compile them for payment and make reports. They used to track the entries in Excel but they wish to do this in a Form = INVOICE TRACKING, be able to query and make reports. My Access knowledge is limited but I have created two tables and the above mentioned Form
The main table= Invoice Tracking (as per the group request) as 37 fields. Starting at the 8th field, data is updated by the users on a daily basis. The source table = XLS 1127 as 7 fields and is refreshed and updated 2-3 times weekly by a live report on the Internet. Up to now, when I need to update the main table, I run an APPEND QUERY. Once this is done, I run a FIND DUPLICATE QUERY and I delete the duplicates manually because some of the first 7 fields will get updated this time or some other time and therefore it will create duplicates Entry Nbr in the Main table. Meanwhile the other 30 fields are populated by users with the information supplied by the invoices. Is there a macro or an expression that could be created to avoid the Query from selecting the duplicates randomly? I have a very basic knowledge of macros and VB but would it be possible to write something that would be like In record #1, IF the field 2 or 3 is empty than look at field 9 and others and if Not Null then get the data in the duplicate record #2, merge the information from the two records?? When the Main table will grow bigger, it will be too much time consuming to delete XXX duplicates and can cause errors.
Hi all: MS Access 2003. I have two text fields family_name and given_name I need to extract 1st, 2nd & 5th letter of family_name along with 2nd & 3rd letter of given_name to form a link_key field. If either name has insufficient letters the missing letter is replaced by the numeral 2. Does anybody know how to help me acheive this please!
Hello, I am working on a database of translators. Each of these translators can have multiple Source Languages, and multiple Target Languages. I understand that I must use a many-to-many relationship, but as the Language fields for both Source and Target Languages comes from one table (tblLanguages), I am having difficulty conceptualizing how I can get the table relationship to produce the desired effect; i.e. having a datasubsheet for each translator with fields for each their Source and Target languages.
My current table structure:
tblTrans TransID (name and contact data)
tblLINK_Language_Trans TransID LanguageID
tblLanguages LanguageID
I thought that maybe if I create a separate LINK table for each Source and Target Language, I might get the desired effect, but this was futile, as only one datasubsheet was shown.
Any advice for a humble Access beginner would be GREATLY appreciated!!!
Does anyone know of an off the shelf application I can purchase to allow users access to my Access database over the web? I have select data I want to allow my customers access to dynamically via the web.
I am familiar with ASP however I am not at a level to develop something from the ground up.
I have access to a Windows Server, an established database and a great desire to get this done.
My vision is to have a daily upload of my back-end (for the sake of current data)to the web server for access via the ASP front end or whatever the case may be.
I am sure to all who read this you understand what I am looking for.
I will definitely entertain hiring someone to work with me on this project if need be. Best case scenario is someone has already done the work and I can just buy it...
I need some help here and any would be muchly apprieciated.
I am building a database for a theme park fast pass system where a customer can book themselves a place on a ride at three session times a day.
Now my problem is, that I need to generate a card number. 5555 1946 as the first 8 digits (this always stays the same) and then the last 8 digits is the customer ID number, which is in the same table. So there are 16 digits in total.
Let me give you an example:
A new customer registers and are assigned a customer ID of 1000 0001. Therefore the Card Number for that customer must be 5555 1946 1000 0001.
I have used auto number for customer ID so when a new customer signs up, there ID is 1 more that highest already in te database.
I've read this forum for quite a while, but just now registered and this is my first post. It's full of great information and I really appreciate all I've learned!
I'm looking to contract / hire an Access Developer for a small project. Essentially, it's taking a CSV file, importing it into Access, then exporting the data within certain parameters into an Excel spreadsheet. There are a few other small details that pertain to how the data is handled in the actual db itself, but that is the overall picture of the project. It's rather small, but is above my Access knowledge level.
My most important goal is getting the DB functional, but then taking the finished product and breaking it down to learn from it.
Please PM me if you're available to assist on this project. Have a great weekend!
I am looking to create a catalog database. It is to serve as a finished product warehouse, as well as a product development tool. There are a number of fields, most of which are straight-forward.
One large problem I have is that the product descriptions are roughly 700 characters. Is there a way to have this information entered into Access and stored either in this database or elsewhere? Any help would be GREATLY appreciated.
I am trying to return the MIN in a numeric field (single result) from my database and I have no issues doing this BUT the problem is that I also need to display additional fields in order to make the result useful. The additional field can't be grouped by b/c that changes the result of the MIN function.
Is there anyway to turn off the rounding function in calculated fields - I need to divide a currency amount by a whole number to calculate the number of full coin bags that will be needed (bags contain different totals according to the coin value) - a whole number.
Then the result is used to calculate how much loose coin will remain.
But regardless of the field type and/or the format, the number rounds when I reduce the decimal places to zero. I need the result to be the whole number and to calculate as the whole number.
I'm an expert user in Excel and am trying to learn more about Access, so I relate many of the functions to what they are called in Excel. And what I'm trying to do right now is count the number of fields in a specific record where the value is a specific result (CountIf).
For example, I need to return the number of fields in a specific record where the value is "Meets Requirements". The specific record will be determined by the Name, Contact, and Email fields (which together comprise the Primary Key).
Is there a way to count the values in multiple fields that equal "Meets Requirements"?
I am trying to calculate the difference in dates between two fields. How do I find the difference in days between field one which contains the date 04/12/2011 and field two which contains the date 04/12/2013? I have tried to use the datediff function, but it keeps telling me it doesn't recognize the field name, even though the spellings correct.
I am new to this forum, and I am facing a problem while learning MS-Access.
I am preparing a database that stores the marks obtained by students in a particular paper in addition to their particulars in tables. A query is then generated to canculate the aggregate marks and result (Pass/Fail) for the student. It is then presented in a report fomatted as a marksheet, as well as one tabulation chart.
The database is very crude in format, but I am happy with it since I do not know programming at all, and still I could make it. I have used in built menu of "ms-access" and mouse clicks only for generating query. It was a learn by doing method.
The problem is that my marksheets require absent students to be marked as "ABSENT" or something of that kind. If I convert my Null values to :
Expr2: IIf(IsNull([E_1]),"ABSENT",[E_1])
It shows ABSENT for null value, but refuses to make column total for E_1; On the other hand if I do not enter such expression, it makes column total in tabulation report, but fails to mark "ABSENT" to those who did not appear. So I have to lose one thing to gain another, while I need both.