Modules & VBA :: Achieve Smallest Possible Number From Among The Largest

Oct 4, 2014

I need to find best combination using Loop to count "NumerOfSheets" To achieve smallest possible number from among the largest. Taking into account additional blocks to allocate. My table before running code looks like

Code:
ID Oder Quantity Blocks NumberOfSheets
1 A 350 2
2 B 200 1
3 C 100 1

At the beginning I was using code (I had no additional blocks):

Code:
Dim recIn As Recordset
Dim strSQL As String
strSQL = "SELECT * FROM tbl1;"
Set recIn = CurrentDb.OpenRecordset(strSQL)
While Not recIn.EOF

[Code] ....

It worked! But now I have new field in my main form "Forms!frmGlowny!FreeBlocks" Where I keep number of blocks to allocate (additional blocks which I can allocate in the column "Blocks"). This filed is count by another code. What is important now, this is positive integer (usually no more than 20). I need find best way to allocate my free blocks. What is best way? - The largest number from "NumerOfSheets" should be as small as possible.

Suppose that this example Forms!frmGlowny!FreeBlocks = 1 (so it's very simple example). So Let's find where I should allocate my 1 free block (I need do it by hand, because I don't have a code:/).

Combination 1

Code:
ID Oder Quantity Blocks NumberOfSheets
1 A 350 3 117
2 B 200 1 200
3 C 100 1 100

Combination 2

Code:
ID Oder Quantity Blocks NumberOfSheets
1 A 350 2 175
2 B 200 2 100
3 C 100 1 100

Combination 3

Code:
ID Oder Quantity Blocks NumberOfSheets
1 A 350 2 175
2 B 200 1 200
3 C 100 2 50

The smallest possible number from among the largest is in the combination No. 2 (because the largest = 175 so it is smallest from all largest numbers of combinations), so now I know that my 1 free block should be added to B order to column "Block". It's very simple example because I have only A;B;C oders and 1 block to allocate. But When I will have e.g orders: A;B;C;D;E;F;G;H and 14 blocks to allocate count by hand will be terrible...

View Replies


ADVERTISEMENT

Querry For Largest Number In Field

Sep 24, 2007

I'm fairly new to access, but I thought this was simple!!! I want to querry a column/field in a database table called Quote # simply to return me the largest number in that column. I then want to use that number and add 1 to it each time I start a new record....
Any help appreciated

View 1 Replies View Related

Nth Smallest Price By Row

May 15, 2007

I am in need of some assistance. I've been looking on here for an answer, but can only find solution that would give me a by column lowest price, and I need to compare the prices by row. What I have is a table of vendor prices for part numbers we sell. What I want to do is compare all the prices the vendors for each part number and return the lowest and 2nd lowest fields in a query. Here is an example...

Part # vendor 1 vendor 2 vendor 3 Lowest Vendor Price Low Vendor #
10526 .75 .97 .67 .67 3
10527 .60 .82 .85 .60 1


Thanks for any ideas....

View 4 Replies View Related

Select Smallest Value

Oct 24, 2005

Hi,
I am a beginner at Access and have tried to search here for help regarding a calculated text field.

I have a problem with a form where I want the smallest of previous values to appear in a text field. I have tried to use the expression builder and iif statements in the control source of the calculated field but I cant make it work. I want to calculate the smallest value for every record, not the smallest value in all records.

Hope someone can help...
Thanks, Sofia.

View 1 Replies View Related

In MS Access 2003, How Can I Achieve The Followings:

Aug 13, 2007

How can I acheive the following in MS Access 2003:

1) Hide the security warning window appears when you I the project/application.

2) Remove the "Microsoft Access" from the title bar and kep the title bar fully empty as exe file.

3) Disable the Alt+Shift to disable the users from viewing the Database Window.

3) Disable the F11 Key

Thanks,

View 1 Replies View Related

General :: Achieve Data From One To Many Relationship Database

Mar 10, 2015

I am using Access 2007, I need to achieve some data from my database, what is the best way to do this.

I have a one to many relationship database, so 1 customer could have many orders, how would you achieve this data?

View 1 Replies View Related

Must Use File Open Command In Access To Achieve Record Locking

Mar 2, 2007

It just read in Access Help that if you have open db using record locking checked that you must open the database using the File=> Open command from the MenuBar. Does anyone know anything about this or can anyone comfirm this a s true?

View 6 Replies View Related

Query Second Largest Value

Jan 27, 2004

Hi, I'm trying to build an expression that will allow me to find the second largest (third largest, fourth largest, etc...) value for a given field. I'm tracking the sales of a company and the database has over 900 customers. I know using the Max fuction will get me the largest value, but how do I find the second largest value?

I've already tried this:

DMax (total_sales, customer_sales, Not Max (total_sales) )


where:

"total_sales" is the name of the field (column)

"customer_sales" is the name of my table

I'd appreciate any help. I know I got the idea right but I'm getting confused with the order of the functions.

Thanks!

Mike

View 5 Replies View Related

How Does One Select The Largest Value In A Field

Jun 29, 2006

So I have another how do i get a form feild to automatically pickup the largest value. it is for an auto number and i want it to show only the last record that was created so it has to be set to show the largest number.
any help would be great.

View 1 Replies View Related

Queries :: Find Largest Value For Each Row?

Jul 19, 2014

I would like to find the largest value for each row in a query. I have a query with several fields, each field has an expression that produces an integer.

Max and DMax seem to pertain to the values in a single field; I need to evaluate values from multiple fields in a single row.

I keep seeing 'range' mentioned but I have yet to see any examples of evaluating a series of data like 'col1;col2;col3' or anything remotely similar.

View 9 Replies View Related

Select Query To Extract All But The Largest Value?

Oct 1, 2006

Hi, newbie question.

I have an existing select Query, that has a field of dates. I want a new select query based on that source that shows all records except for the one with the largest value date. There will be no duplicate dates. I tried:

SELECT Q_Tasks_Accs.End AS NotLatestEnd
FROM Q_Tasks_Accs
WHERE (((Q_Tasks_Accs.End)<(Max([Q_Tasks_Accs].[End]))));


but when I run the query I get error message:

"Cannot have an aggregate function in WHERE clause(Q_Tasks_Accs.End)<(Max([Q_Tasks_Accs].[End]))"

I clicked on Help but did not understand what it said. So any help from here would be appreciated.

Thanks

View 2 Replies View Related

Queries :: Select Largest Value Which Is Smaller Than Another Value (Access 2007)

Jun 4, 2014

I have a table of logged entries. Each record has a date field (ValueDate) and an account identifier field (AccountID)

I also have a table of rates. Each record has the same account identifier field (AccountID), a date field (EffectiveDate) and a rate field (BankRate)

Entries can be logged for any given ValueDate. But there may or may not be a corresponding EffectiveDate in the rates table.

I need to write a query that will return all of my logged entries and the largest EffectiveDate which is on or before the ValueDate (as well as the BankRate corresponding to that EffectiveDate)

This is as far as I've gotten but it returns multiple records for each logged entry. I need one record per logged entry.

Code:
SELECT tblLoggedEntries.EntryID, tblLoggedEntries.AccountID, tmp.BankRate, MAX(tmp.EffectiveDate) AS EffectiveDate
FROM tblLoggedEntries
LEFT JOIN
(SELECT tblRates.AccountID, tblRates.BankRate, tblRates.EffectiveDate
FROM tblRates) AS tmp ON tblLoggedEntries.AccountID = tmp.AccountID
WHERE tmp.EffectiveDate<=tblLoggedEntries.ValueDate
GROUP BY tblLoggedEntries.EntryID, tblLoggedEntries.AccountID, tmp.BankRate

View 11 Replies View Related

Queries :: Compare Data In 3 Fields In 1 Table / Group By Largest

Dec 4, 2013

I'm trying to create a query that will compare the data in 3 fields in a record, choose the largest (I also have a criteria to order by if more than 1 field has the same entry and it's the largest of the 3), and then group by that.The fields I will need are as follows:

PRODUCT table:
ProductName
Chemical
ChemicalAbstract
PhysicalState
NFPAHealth
NFPAFlammability
NFPAReactivity

qryQuantityOnHand query (which doesn't link directly to the PRODUCT table, it links through associations with other tables):QOH...I will eventually need information from another table for the final reports, but I don't think it has to be included in this query.

The fields NFPAHealth, NFPAFlammability, and NFPAReactivity each may be 0, 1, 2, 3, or 4...I need to ignore blanks; if 1 of the above fields is blank, they will all be blank.For any record, I need to compare the number in those 3 fields to each other, and choose the largest number and group by that rating.

In other words, if the largest of the 3 numbers is a 3 in the NFPAFlammability field, all those products need to be grouped together.If the same number appears in at least 2 of the fields, the order that determines the grouping is: Flammability, then Health, then Reactivity..Ultimately the report will be grouped as follows:

Flammability
Rating 4
Product 1
Product 2
Product 3

Rating 3
Product 1
Product 2
Product 3

Rating 2
Product 1
Product 2
Product 3

Health
Rating 4
Product 1
Product 2
Product 3

[code]....

and each of the groups will be sub-totalled.I'm stumped at trying to create the query in the first place.The added aggravation here is that we are dealing with 23 stores, each with their own mix of products. I have another table that contains the information about which products are in which store.

View 4 Replies View Related

Modules & VBA :: Sequence Number In Query Use A Starting Number

Sep 20, 2014

creating sequence number in a query using a starting number. For example i want to use the starting sequence number as 5

---SEQNUM---------COLOR-----------
-----5------------------blue--------------
-----6------------------red---------------
-----7------------------orange-----------
-----8------------------black-------------

View 2 Replies View Related

Modules & VBA :: Put 0 Before The Number If It Is Less Than 10?

Aug 6, 2014

The following code copies data from Access table to Excelsheet1. But the thing is when it combines Type,Type1 and Type2 in the query then i want to put some condition as below:

if Type1 value is less than 10 then put 0 before Type value
if Type2 value is less than 10 then put 0 before Type1 value.

e.g Type=5, Type1=8, Type 2=19 then in the sheet1 it should show: 50819 but at the moment it shows 5819.

Code:
strsql = "Select CDate(Format(Scandate,""0000-00-00"")) As [Scan_Date],batchno,ScanBoxID,envelopes,cases,pages,Type & Type1 & Type2 from Table1 where (Type=2 or type=3) and scandate =" & J
rs.Open strsql, cn
Set ws = ThisWorkbook.Worksheets("Sheet1")
ws.Range("b8:I1000").Clear
ws.Cells(8, "B").CopyFromRecordset rs
ws.Cells(2, "G").Value = J
rs.Close

View 3 Replies View Related

Modules & VBA :: Check ID Number Between Range

Oct 23, 2014

I'm trying to create some code that will create a new folder depending on the ID that is currently being added to the database.What happens at the moment is a new ID is generated which in turn is job reference.When this is added to the database a folder is created with a prefix of this ID number and a 20char test specified in a text field by the user.

What I am trying to achieve is this:If the ID = 57...Then a folder is create called 1 - 500 (and ignore if one has already been created, which it should have at ID number 1)...When the ID Number 501 comes along another new folder is create called 501 - 1000 etc etc.The idea is not to have 3000+ folders in just one folder making it look a bit messy and lengthy to look through.

View 3 Replies View Related

Modules & VBA :: Compare Currency To Number?

Dec 4, 2014

I'm trying to compare a Currency formatted field to a Number formatted one and getting wrong results.other then formatting the Number as Currency too ? Tried to use Val() but the Currency returned 0

View 7 Replies View Related

Modules & VBA :: Add Page Number To Header?

May 16, 2015

I'm using VBA to insert the page number in a header. It's working, exept for a couple of things. I want it to insert the page number at the current position, and restart numbering at each section. I increment the section # with the variable x. Currently, it's inserting the page number at top-left of header. I want it to insert the page number after the word "Page" followed by 2 lines breaks.

Here's snippet of my code:

'Create Header
With ActiveDocument.Sections(x)
.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
.PageSetup.DifferentFirstPageHeaderFooter = True
.Headers(wdHeaderFooterPrimary).Range.Font.Size = 9
.Headers(wdHeaderFooterPrimary).Range.Text = "Session: [" & rst!SessionNum & "] " & rst!SessionTitle & _
Chr(13) & "Presenter: " & rst!Full_Name & Chr(13) & "Page " & Chr(13) & Chr(13)
.Headers(wdHeaderFooterPrimary).PageNumbers.Add pagenumberalignment:=wdAlignPageNumberLeft, FirstPage:=True
End With

View 5 Replies View Related

Modules & VBA :: Adding A Number To A Field

Nov 11, 2013

I have a table with 100,000 plus unique rows and I want to add a column (call it 'ID') and place a value in each row starting with 000001 and adding one on to each row. What is the correct code to do this. I've tried with various combinations of For...next but can't get anything to work.

View 3 Replies View Related

Modules & VBA :: Using Record Number In Where Statement

Jul 8, 2014

I have a form with a sub form based on a query, in one of the fields i use a dbl click to open another form. I have use this in several areas in my DB but i having issues in one section of it not opening to the correct record. i tried a few things but i am limited to what i can use. The Record_Number is an Auto number and CLASS_Num is an entered number buy the user.

I have 2 things that i can use but i can not get the Record_Number to work. When i use the Record_Number i get an Data Type Mismatch Error.

----------------------------------------------------------------------
Private Sub Combo10_DblClick(Cancel As Integer)
DoCmd.OpenForm "Documentation_Form", acNormal, , "[Record_Number] = '" & Me.Record_Number & "' and [CLASS_Num] = '" & Me.CLASS_Num & "'"
End Sub
-----------------------------------------------------------------------

View 3 Replies View Related

Modules & VBA :: How To Check If A Number Is Divisible By 6

Feb 1, 2015

is there a function that will let me check if a value that was input is divisible by 6?

View 2 Replies View Related

Modules & VBA :: Generated Random Number Always The Same

Jun 2, 2015

I have a log in screen that my users must use before they can use my db. if they enter the wrong username/password they get the usual message boxes. I also thought it would be a nice personal touch if once they've logged in they get a little greeting, so i made a message box that says "Hello " followed by their first name

This did the trick for a while, however theyre sick of seeing "Hello" and want other greetings, i figured this wouldnt be too complicated and took me only about 10 minutes or so to implement.

Basically i created a table (tblGreetings), has two fields, an autonumber field (ID) and a short text field

I've added the following code into the login sequence:

Dim greetings As Integer
Dim greet As String
Dim randomNum
greetings = DCount("ID", "tblGreetings")
randomNum= Int((greetings - 1 + 1) * Rnd + 1)
greet = DLookup("Greeting", "tblGreetings", "[ID]=" & randomNum)

which in theory should generate a random number between 1 and "greetings" (which is an integer representing the number of greetings ive stored in my table), currently greetings=9

then it should pick a greeting from tblGreetings using the random number as an ID

This more or less works, except whenever the DB is opened and a user logs in, the "random" number is the same every time, it always seems to be 7 (which corresponds to the greeting "G'day").

Why this random number is always the same? it changes if i run the code a few times in the same session, but once the database is closed and reopened it still gives off the number 7, every time

View 3 Replies View Related

Modules & VBA :: How To Refer Object By Its Name When Name Is A Number

Sep 12, 2014

Actually in a powerpoint slide, I am having a set of 31 shapes having their names as numbers from 1 to 31.

How to refer by its name?

By hardcoding I refer it like this:

activepresentation.slides(1).shapes("1").someprope rty = somevalue

How to do it in a loop?

Code:

for i = 1 to 31
activepresentation.slides(1).shapes(i).someproperty = somevalue
next i

The above code will refer the shapes only by the index. But the shapes are not having index and name as same.

View 9 Replies View Related

Modules & VBA :: Text To Number Conversion

Sep 12, 2013

I have some vba that dump an access table into a recordset and then into an excel spreadsheet. When the data is exported Columns I:Q (which are numbers) appear as text (with the green triangle in the upper left corner). I have a pivot table that refreshed however it can't do anything with text.

I've tried just to change the cells format and it doesn't work. The only way I've been able to change it to a number is to click on the green triangle and select "Convert to Number" How can I do this via VBA? The # of rows will change but the columns will always stay the same.

View 2 Replies View Related

Modules & VBA :: Naming A File - SOW Number

Oct 23, 2013

I'm currently working with Access 2007 building a way to create PODs to clients. I have most everything laid out, one problem I can't seem to get around is naming the file the SOW #. Below is the code:

Function Run_all_PODs_01()
Dim myPath As String
Dim name As Object

DoCmd.OpenQuery "Q5 SOW bill requested data points all", acViewNormal, acEdit
DoCmd.OpenQuery "Q5 SOW bill requested All 01", acViewNormal, acEdit

[Code] ...

I can't seem to get the name to equal the SOW number.

The table that I'm trying to reference is "SOW bill requested data points" it is a basic table one row with a column header as SOW #. I'm not sure how to tell it name the file that data point in the column.

View 4 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







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