Modules & VBA :: Count Total Number Of Integer In A List

Oct 7, 2013

In one table, I have a few fields. One of the field is "ItemSequence" and another one is "TotalPcs"."ItemSequence" is where user key in the sequence number for one or more item. 5 example for possible content of "ItemSequence" is as following :

1) 7
2) 4,6,9
3) 5-9
4) 3,5,9, 23-25
5) 3-5, 8-10

"TotalPcs" is the total number of items key in to "ItemSequence". For the 5 example above, the related "TotalPcs" should be as following:

1) 1 (1 item, which is item 7 alone)
2) 3 (3 item which is item 4, 6 and 9)
3) 5 (5 item which is item 5, 6, 7, 8 and 9)
4) 6 (6 item which is item 3, 5, 9, 23, 24 and 25 )
5) 6 (6 item, which is item 3, 4, 5, 8, 9 and 10)

For time being, the user have to count manually to get the "TotalPcs". I wonder is there a way to calculate the "TotalPcs" by programming?

View Replies


ADVERTISEMENT

Modules & VBA :: Calculate Integer Number Difference From Two Dates

Sep 20, 2014

Basically, I am trying to calculate a integer number difference from two dates (TAT = Due-Date - Result_Date). The number is calculated and excludes weekends and ideally holidays (for that I have a tblHoliday but not sure how to use it). The function below seems to calculate a number but doesn't exclude weekends.

For example, if Due_Date is 9/26/2014 and Result_Date is 9/30/2014, then TAT is calculated to be 5 (should be 2).Since 9/26/2014 is a Friday only Friday and Monday are used in the calculation.

Code:

Option Compare Database
Public Function WorkingDays(StartDate As Date, EndDate As Date) As Long
Dim intCount As Long
intCount = 0

[code]...

View 1 Replies View Related

Queries :: Count Total Number Of Records

Dec 18, 2013

I am wanting to display in a text box or on my report the total number or records in my database. Also I have some buttons that filter the results a little, I'm wanting to display the number after I hit the button(s). Would I just add the query to the end of each button I have?

View 6 Replies View Related

Queries :: DISTINCT COUNT Of Name If Total Number Of Items Greater Than 0

Jan 29, 2014

I have 2 tables linked with a 1 to many relationship by NAME. Tables look like this....

TBL-STORE

NAME ADDRESS
Walmart 12 Nowhere
Target 14 Somewhere
Lowes 10 Anywhere
Sears 16 Nowhere

TBL-PURCHASES

NAME [NUMBER OF ITEMS] [PURCHASE DATE]
Walmart 4 1/4/14
Walmart 2 1/5/14
Target 0 1/5/14
Lowes 3 1/5/14
Sears 1 1/5/14
Sears -1 (returned to store) 1/6/14

I want a DISTINCT COUNT of [NAME] if Total[NUMBER OF ITEMS]>0, so the correct number will be 2 in the example.

This is one way I've tried to write the SQL, but I keep getting an error...

SELECT Count([TBL-STORE].[NAME])
FROM [TBL-STORE] INNER JOIN [TBL-PURCHASES] ON [TBL-STORE].[NAME] = [TBL-PURCHASES].[NAME]
WHERE ([TBL-PURCHASES].[NUMBER OF ITEMS]>1)
HAVING ([TBL-STORE].[NAME])="DISTINCT");

I also tried an Count(IiF( and can't get that to work either..

View 3 Replies View Related

Queries :: Count Same And Differences / Calculate Percentage Of Number Of Same Over Total Amount

Jul 9, 2013

I am trying to count how many of the "same" and "differences", as well as calculate the percentages of the number of "same" over the total amount. To clarify, I work at a nursing home, and I need to calculate the number of people who were admitted to our facility and then to the hospital for the same diagnosis, and a different diagnosis. Then, out of the total number of people who were admitted to the hospital from our facility, I need to calculate how many of those people had the same diagnosis or a different diagnosis.

Also, I need to categorize these diagnosis by each type of diagnosis.

View 14 Replies View Related

Modules & VBA :: Total Count Of Unique Values In A Query

Jan 13, 2015

I have the following code:

Code:
Dim rs As DAO.Recordset
Dim db As Database
Dim strSQL As String
Set db = CurrentDb
strSQL = "SELECT DISTINCT tbl_contract_lev.ContractID FROM (tbl_leverancier_gegevens INNER JOIN

[Code] ....

The result of the query is a list fo unique values but by including the "count" function in SQL seems not te be working in combination with "DISTINCT"...

View 5 Replies View Related

Modules & VBA :: Count Total Working Days Of Month

Mar 5, 2014

I have a table with two fields named as "Month" and "Bank Holidays". I have put names of the month in this table for 2014 and the corresponding bank holidays of each month. Now I want to write down the piece of code that will execute when a button is pressed and check the current month of the year and then display the total working days ( After subtracting bank holidays of that month and weekends of that month from the total working days of that month).

View 2 Replies View Related

How To Send Count(*) --> Declared Integer

Mar 14, 2006

SQL Query
SELECT COUNT(*)
FROM Orders
WHERE (((Orders.Date) = [forms]![frmOrders]![DTPdicker2]))
VBA CODE

Option Compare Database
Dim iDay As Long
Dim iCount As Long

Private Sub DTPicker2_Change()
iDay = 0
iCount = 0
iDay = Weekday(Me.DTPicker2.Value)
iDay = iDay * 100
'iCount = Count(*) from SQL query above'
iDay = iDay + iCount
Me.txtRefNumber = iDay
End Sub


Basically I am trying to generate a meaningful reference number while adding new orders rather than using an ever growing unique id(AutoNumber), for creating Weekly Reports.

I have tried using the following code
iCount = DoCmd.RunSQL (qryReturnCount)
and I get an error

Any help would be greatly appreciated.
Last question for the gurus out their can it be done with the expression builder? To save me banging my head against VBA syntax.:mad:

Cheers Andy!!!

View 2 Replies View Related

How To Cast A String Into Integer Or A Real Number?

May 8, 2007

Iff(fico>600,1,0) as g,
I found fico is a string in access table. so the above does not work.
How to fix this problem
Thank you very much.

View 3 Replies View Related

Modules & VBA :: Count Number Of Rows In A Table?

Nov 10, 2014

I need to write a code that checks if every 6 lines in a table contains a string. If it contains the string, then carry on looping, but if it does not, it will delete the current line and the previous 6 lines before it. The program should then continue looping through the entire table.

For example,

Code:
Apple
a
b
c
d
e
Apple
f
g
h
i
j
Apple
l
m
n
o
p
q
Apple
.
.
.

I need to find the string "apple" in every 6 lines. So, that means that the first 2 Apples are fine, but for the third one needs to be deleted as it contains 7 lines instead of 6.

View 14 Replies View Related

Modules & VBA :: Count Number Of Fields Have X As A Response

Nov 20, 2013

I have a form that records followup activities for protocols. The form allows the user to enter up to six f/u actions from a dropdown menu in six separate fields (called fu1_action, fu2_action, etc).

I am trying to write a query that retrieves only protocols that only have one f/u action selected as "telephone correspondence" and am having trouble. It seems I could write a function in VBA that would somehow loop through the 6 f/u action fields and give a value of 1 to those that have 'telephone correspondence' as a response, and then add them up to give a total of calls for that specific protocol, and then in a separate query only retrieve those that have a total number of calls = 1, but how to get started in writing this.

View 3 Replies View Related

Modules & VBA :: Count Number Of Lines In A Text Box

Oct 17, 2014

I have a memo field that feeds to a textbox control on one of my forms. I would like to re-format the textbox using the .Height value based on how many lines appear in it (i.e. it will fit only 3 lines if there are 3, but 5 lines if there are 5, etc.).

Is there any way to count the number of lines that appear in the textbox?

View 3 Replies View Related

Modules & VBA :: List Box To Show Recordset With Record Count

Sep 22, 2013

I have the listbox named "payment_date", which shows recordset specified by following code:

Code:
Private sub Form_Current()
Dim que As String
que = "SELECT [date] FROM payments WHERE id Like '" & Me!myid & "*' ORDER BY [date] desc;"
Me.payment_date.RowSource = que
End Sub

I need my listbox to show recordset with record count like this:

3.date
2.date
1.date

View 4 Replies View Related

Modules & VBA :: Count Number Of Records With Date From A Table

Sep 24, 2014

I have a table which specifies the delivery date

I have a from that allows you to choose a year and a month.

I have an unbound textbox which I wan to display the count

I want to be able to count all the records from a table with the year and month specified in the comboboxes and display this in the texbox.

View 4 Replies View Related

Modules & VBA :: How To Count Number Of Events Based On Type

Dec 3, 2014

I have a table that contains many records of events. I've already created a multiple item form based on the table. My form contains 2 textboxes for input of a date range and a dropdown box to select "yes or no".

What I am having difficulty with is the query that will count the records by type insert it into the recordsource such that the multiple item form will appear like this:

Event Type| Count
Input | 4
Output | 2
Update | 3

How do I go about doing so? I have been testing with this simple query:

Code:
Private Sub Command8_Click()
Dim Task As String

Task = "SELECT EventType, Count(EventType) FROM Final GROUP BY EventType;"
Me.RecordSource = Task
End Sub

But the column that contains the count keeps appearing as #name?

View 12 Replies View Related

Modules & VBA :: Count Of Serial Number In Email Body

Jul 15, 2013

I am attempting to modify some code that is used for reading content in an Outlook mail and need to catch and move the email if certain content is duplicated in the email.

The code reads the email that is in the attached image format:

As seen, this email contains 2 devices, but the Serial No in both is duplicated.

In the code, I need to capture this and rather than reading the contents, I need to just move this email to a separate "Manual" folder to be dealt with separately, so not to write the information to the database.

The current code is as follows:

Option Explicit
Private ns As Outlook.Namespace
Private sEmailAddress As String
Private sPerson As String
Private dReceived As Date

[Code] .....

View 4 Replies View Related

Modules & VBA :: Code To Count Number Of Tables In Database?

Jan 17, 2015

creating the VBA code to find the total number of tables in my database.

View 2 Replies View Related

Modules & VBA :: How To Count Number Of ROWs In Query Result With Variables

Aug 8, 2013

I am trying to count rows in the result of one of the queries and I am having a bit of trouble getting it going.

The current code - this is executed as on-click event when clicked on List Box feed with query below.

What I want to add is simple if that when number of rows produced by the querry is 1 it will enable a picture item in the different part of the form, however it does not want to count the rows for me.

Code:
Private Sub search_items_Click()
Me.OBSFullFilledOrdersHolder.Enabled = True
mysql = "SELECT orders.[order id] , STUDENTS.[first name]& ' ' & students.[surname] AS Name, students.[contact name] AS ContactName , ORDERS.[Online Bookshelf order] AS OBS , STUDENTS.[Delivery Address 1], STUDENTS.[Delivery Address 2], STUDENTS.[Delivery Address 3], STUDENTS.[Delivery Address 4]"

[Code] ....

The query itself works when tested but when used in code with DCount function will return error: Run-Time 2471 the expression you entered as query parameter prouced this error

'[Forms]![FULLFILL ORDERS]![search items].[Column(0)]'.

View 5 Replies View Related

Modules & VBA :: Count Number Of Text Files In Directory Sub Folders

Mar 14, 2014

create/find code that will count the number of text files in a directory with one level of folders please see below:

Directory path is : B:

First and only level of sub folders:

there are 100 of these and they all end in ".fof"These .fof folders will always contain .txt files.I've tried using the following code, but it always returns No files found.

Code:

Dim lngFileCount As Long
Dim StrFileName As String
StrFileName = Dir$("B:*.txt")
Do While Len(StrFileName) <> 0

[code]...

View 1 Replies View Related

Queries :: Access 2007 - Update A Field In A Table With A Random Number / Long Integer

May 27, 2014

Is it possible to run a SQL command to update a field within a table with random numbers?

More specifically - random long integers linking back to an ID (autonumber) field in another table?

Background to this is, I have multiple static data tables related to each other by long integer identifiers (autonumbers)

The structure is fine but I haven't been provided with the actual data yet - but for development purposes, I need to work on other functionality which requires that this data be present.

So I want to fill my table with dummy data such that I can go off and work on the remaining functionality, but then just go back and clear it all out once I get the actual data.

I have one 'main' static table, which links back to other tables, which I have already populated with dummy static (i.e. company names, locations etc) Now I want to go into my main table and populate those fields in each record with a random ID. I don't mind doing this field-by-field (there's only a handful) but I've a lot of records in there (~1000) so I'd rather not do this record-by-record.

View 6 Replies View Related

Modules & VBA :: Count Number Of Unique Records Based On Range Of Date

Jan 19, 2015

Code:
' count records in query
Dim rs As DAO.Recordset
Dim db As Database
Dim strSQL As String
Dim beginDatum As String
Dim eindDatum As String
Set db = CurrentDb

[code]....

View 4 Replies View Related

Modules & VBA :: Count Number Of Times Mouse Left-clicks On Active Form

Jun 14, 2013

I would like to update a txtbox with a simple int count of the number of times a mouse is left-clicked while on an active form. How do I do this?

View 5 Replies View Related

Modules & VBA :: Changing From Integer To Text

Nov 23, 2014

I am having a query which having a category field like Electrical, Sports, House hold etc.

What I want that if i select Electrical then it should return 15, if Sports then 10 and so on i think this could be done through this below mentioned VBA but it need change from integer to text...

Option Compare Database

Public Function fncGrade(intNum%) As String
Select Case intNum
Case 0 To 1: fncGrade = "Same as Previous"
Case 2 To 32: fncGrade = "C-3"
Case 33 To 40: fncGrade = "C-2"
Case 41 To 50: fncGrade = "C-1"
Case 51 To 60: fncGrade = "B-3"
Case 61 To 70: fncGrade = "B-2"
Case 71 To 80: fncGrade = "B-1"
Case 81 To 90: fncGrade = "A-2"
Case 91 To 100: fncGrade = "A-1"
Case Else:: fncGrade = "X-X"
End Select
End Function

View 5 Replies View Related

Modules & VBA :: Return Integer Based On Time?

Oct 30, 2013

I have a query with a Start Time where the need to return a set integer in another field in my query. I am attempting to get this to work in my StripSecondsQry.

I am not getting any error messages and I am not getting any output, When I view this in the Locals window I can see that it should be returning 7, but instead I get nothing unless I change it to

Code:
Function SortStart(StartTime As String) As Integer

then I get zero.

I had this working within the query, but I had to add one more time and then received a message that the expression was too complex.

Code:
Sort_Start: IIf([StartTime]="7:00 AM",1,IIf([StartTime]="8:00 AM",2,IIf([StartTime]="8:45 AM",3,IIf([StartTime]="9:00 AM",4,IIf([StartTime]="9:15 AM",5,IIf([StartTime]="10:00 AM",6,IIf([StartTime]="10:15 AM",7,IIf([StartTime]="10:30 AM",8,IIf([StartTime]="12:00 PM",9,IIf([StartTime]="1:30 PM",10,IIf([StartTime]="1:45 PM",11,IIf([StartTime]="2:00 PM",12,IIf([StartTime]="3:00 PM",13,IIf([StartTime]="4:00 PM",14))))))))))))))

View 3 Replies View Related

Modules & VBA :: SQL CAST Function - Return Integer Value Of String

Aug 28, 2013

Need to use CAST to return integer value of string (digits as data type string).

Where clause looks like this:

... Where Cast([Price File] as int) > 0

works fine in SQL Server but not sure what syntax is in VBA . Using Paul Baldy's suggestion to set Select statement as string and do the debug.print to verify that SQL has no goofs ... looks good but not to Access. What is proper syntax?

View 12 Replies View Related

Getting Total Count

Oct 28, 2005

One of the tables in the database has these fields

st1: st2: st3: st4: Date:
pass fail fail pass 10/21/05
fail pass fail pass 10/22/05

and so on. What I need to do is extract the number of passes and fails on each of the four stations and put them into a report. User will have to enter either one date or a date range.

Right now, i'm having to create a 8 queries for to find Count of Pass and Fail on each station and make a master query. And I because it's not grouping everything together I can't figure out a way to get a date range...

Please help,

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved