Modules & VBA :: Getting The Value From A Table

Apr 18, 2014

I've got a bit of a problem with determining the max value in the table. I have a table called "Functions" and a column: "Function_KSW". There are values as follows:

281A01
421A01
281A02
etc.

I want to get the max value of them but under the condition that first three chars are e.g 281 so the max function will take only max from a narrowed criterion. The chars are to be selected from combolist in a form. I have written something like this:

Code:
Private Sub Click1()
Dim max As String
max = DMax("Function_KSW", "Functions", "Function_KSW like " * 281 * "") // here 281 for the test's need
// should be: like " * [Forms]![Form1]![ListBox0]*"?

[Code]....

BTW. When I want to find the max by the SQL in the query and based on the value to sort in combolist in the form, sorting doesn't work as well. When the dirtect value (here 281) is written in the code it is working. Seems that those ** stars unable to retrive the vaule from the combolist

View Replies


ADVERTISEMENT

Modules & VBA :: Split Table Record Into Multiple Records / Rows In A New Table

Nov 10, 2014

In a situation where I imported an excel file with so many columns and split them into two temp tables and they are linked using a key.

the data has a fixed part lets say

Field1....Field2.....Filed3.....Field4...then Field5.....Field6.....Field7....Field8 is the same data range as Field9...Field10...Field11...Field12. I would want to split this data into multiple rows like this

Field 1 Field2 Field3 Field4 Field5 Field6 Field7 Field8
Field 1 Field2 Field3 Field4 Field9 field10 field11 field12 and so own...

What is the best approach?

View 3 Replies View Related

Modules & VBA :: Copy Record To History Table And Then Delete It From Main Table

Jul 9, 2014

I have a form with a sub form. when a record is choosen in a combo box the sub form is filled out with a record.

what I am trying to do is have a button that will copy that record to a history table then delete it off the the main table.

I cheated by using the wizard to get the code to delete the record but I am having troubles modifying the code to copy that record to the history table. Here is the code below. I have tried to insert code in several places but it just errors out.

'------------------------------------------------------------
' Master_tbl_sub_fm
'
'------------------------------------------------------------
Function Master_tbl_sub_fm()
On Error GoTo Master_tbl_sub_fm_Err
With CodeContextObject
On Error Resume Next

[Code] ....

View 8 Replies View Related

Modules & VBA :: Generate Multiple Records In One Table From Single Record In Another Table

Sep 20, 2014

I am building a simplified re-order point system - if inventory position drops below a certain level (the yellow level is this case) one or more purchase order lines has to be created in another table.

I have one table with the following field and data:

ItemId Red Yellow Green Multiple Inventory position
0001 10 30 50 5 45
0002 5 40 47 5 23
0003 11 20 30 10 5

I would like to generate new records (in another table) based on the above fields and three records.Basically the end result should look as the following:

ItemId Qty Start inv Aggregated inventory Prioritization
0002 5 23 28 Yellow
0002 5 28 33 Yellow
0002 5 33 38 Yellow
0002 5 38 43 Green
0002 5 43 48 Green
0003 10 5 15 Red
0003 10 15 25 Yellow
0003 10 25 35 Green

The logic is quite simple - if inventory position is less than the yellow value new order lines should be created in multiple qty (based on the multiple field) until the aggregated value (in table 2) is above the green value.The priotization value should be based on the start inv (in tbl 2) compared to the values in red, yellow and green in tbl 1.

View 8 Replies View Related

Modules & VBA :: Restrict Value In Lookup Field To Only Include Values From Table B Not In Table A?

Feb 2, 2014

I have a database that has 2 tables. Table A and Table B. Table A is my primary table. On this table I have 2 fields. The first field is a LOOKUP Field that looks up information from Table B and displays my selection in the field on Table A. Then using DLOOKUP I automatically input the information in the Second Field on Table A based upon the selection from the First Field.

This is working mostly correctly. However, the problem is, when I click on the next record in the table, it automatically changes the Second Field on that record to the same value as the record before it and continues this trend each time I click on another record. This occurs without me making a selection in the first field. If I make a selection in the first field it does change the Second Field to the Correct Value, but then the next Record has the same issue.

How do I go about fixing this so it doesn't change the value with the change of the record. Only change if I change that particular field within that 1 record?is there a way to restrict the Value's in my lookup field to only include the Values from Table B that aren't already in Table A?

View 5 Replies View Related

Modules & VBA :: Parent Table Revision History - Insert Multiple Records Into Child Table

Sep 8, 2014

I have a parent table (tblLabels) and a child table (tblRevision) where the revision history for the parent table is kept.

The parent table is populated via an excel import and may have several records imported at once. Instead of having the user manually enter a new record note in the child table for each record imported into the parent table, I've created a form that collects the necessary data (date, person who added the record, person who authorized the record, and notes) and then creates a revision history for each new record.

This is what I have so far:

Code:

Private Sub cmdAddNotes_Click()
Dim strSQL As String
Dim RevisionDate As String
Dim RevisionRevisedBy As String
Dim RevisionDesc As String

[Code] ....

When I run the code nothing happens. No error, no new records create, etc. My suspicion is that I may need to use an INSERT INTO query instead of an UPDATE query, but I'm not sure how to go about matching up the foreign keys if that's the case.

View 14 Replies View Related

Modules & VBA :: Add Rows To Table Based On Record Count Of Another Table

Mar 10, 2015

I am trying to assign teams to players. I have an import table with all of the players information listed. What I want to do is determine the count of players in a given city. For every 9 players I want to add a new record to the Team table and assign the team number (auto incremented for each team created). Then I want to add the players to the Players table with the Team Number that was created.

View 8 Replies View Related

Modules & VBA :: Update Access Table From SQL Server Table Source

Jun 17, 2013

I have created a code below to test whether I can run a query and retrieve a data from an SQL server table. And so far I can return the result using a messagebox. but somehow I just don't know how to use this connection to update the table inside this access file. Basically I want to use this as a front end file. then when the form is open it will automatically update the table inside this access file and load the data to the combo box as a list.

Code:

Option Compare Database
Sub LocalServerConn_Test()
Set conn = New adodb.Connection
Set rst = New adodb.Recordset

[code]....

View 4 Replies View Related

Modules & VBA :: Copy Structure Of A Table To Make A Temp Table

Apr 20, 2015

I'm trying to copy the structure of a table to make a temp table. I'm using CopyObject (which also copies the data). So when I delete the data from the temp table, it also deletes data from the source table. Is the data linked? It should just be deleted from the temp table. Below is the beginning of the code. I've stepped through, and at the last step shown, the data in the source table deletes.

Code:
Dim strFile As String
Dim temp As String
Dim tbl As String
Dim db As DAO.Database

' error handle
On Error GoTo F_Error

[Code] .....

View 3 Replies View Related

Modules & VBA :: Identify Strings Into 2nd Table Records Then Update 1st Table

May 5, 2015

MS Access 2013: I have two database tables as below:

tbl1_MainDB --- It has a field named as "City" where I get huge data for some city names. Sometimes This field may have some unknown/new names which are not listed in our 2nd table ("tbl2_RefrDB")

tbl2_RefrDB --- It's a reference table which has raw names for cities, and then standard names of their city and state in another fields.

Target --- I want to create a VBA prorgram (Sql query) which can look from tbl1_MainDB.[City] to tbl2_RefrDB.[Raw_City] field, and if found then pick the "Standard_State" and "Standard_City" record values from there, and update into the 1st table "tbl1_MainDB".

...if not found in "tbl2_RefrDB" table, then user can be informed & ask for updating the new/unmatched city record as a new record in this table.

Attached sample database for more details.

View 4 Replies View Related

Modules & VBA :: SQL String - Append Records From Table Into Another Table

Mar 21, 2014

I have a form with a listbox that displays the name of a table. Once the listbox item is selected, the table name is set to a variable called myFile. I want append the records from the table (myFile) into another table.

View 1 Replies View Related

Modules & VBA :: Update Column In Table Based On Another Table

Apr 24, 2015

I'm trying to use VBA to update a new column in a table with info I already have in another table.The table I want to update is an inventory details table, it has around 25,000 records. I added a column called "UnitCost", of course the column is empty for all 25,000 records so I would like to fill it easily using DoCmd.RunSQL "UPDATE" feature.

I use that through-out the program however I'm unable to connect the dots for this one.What it needs to do is update "UnitCost" in "InventoryDetails" from "Products" where "InventoryDetails.ProductNumber" = "Products.ProductNumber"

The "Products" table has all the different unit cost, it just need to be placed in the "InventoryDetails" table for every record. Of course product1 needs products1 unit cost and product2 needs products2 unit cost, etc.

View 1 Replies View Related

Modules & VBA :: Add Records To A Table Referencing A Table In Another Database - DAO

Jan 16, 2015

I am using Access 2010 and I currently use a command button on a form to add new records to a table using data that the user has entered into the form using the code below:

Although this is pretty self-explanatory, here is a key for reference:

Me.lstFacilities = ListBox
Me.cboMeasure = ComboBox
Me.cboYesNo = ComboBox
Me.txtTarget = TextBox

Code:
Private Sub cmdAddMet_Click()
Dim DB As DAO.Database
Dim RS As DAO.Recordset
Dim strSQL As String
Dim i As Integer
Set DB = CurrentDb

[Code] .....

This works great but I would like to be able to pull in data from another database based off of Me.lstFacilities.Column(1, i) which is the FACILITY_ID field and is located in the other database's table. I thought about adding in another string variable(strSQL1) and opening up a separate recordset and database:

Code:
Set DB1 = OpenDatabase("serverotherdb.accdb")
strSQL1 = "SELECT [FieldName] FROM [tblOtherDatabase] IN 'serverotherdb.accdb'"
Set RS1 = DB1.OpenRecordset(strSQL1)

However, I'm not sure where to start pulling in the data from the [fieldname] in the [tblOtherDatabase] when I start the loop below:

Code:
For i = 0 To lstFacilities.ListCount - 1
If lstFacilities.Selected(i) = True Then
RS.AddNew
RS!RELATIONSHIP_ID = Me.lstFacilities.Column(0, i)
RS!MEASUREMENT_PERIOD = Me.cboMeasure

[Code] .....

Is it even possible to do this?

View 10 Replies View Related

Modules & VBA :: Updating Master Table From Temp Table

Jun 5, 2013

I have two tables that are formatted identically....

Table1 = MasterTable
Table2 = TempTable

I am taking a copy of one of the entry from the master table and Copying it to the temp table.I then open a form on the TempTable that enables the user to modify the content without affecting the information in the MasterTable.On Completion and Save I wish to take this modified content and update the MasterTable Using the Field "ID"

the tables for example look like this

ID NAME AGE DATE1 DATE2

I am guessing I need to use a

Code:
DoCmd.RunSQL UPDATE "MasterTable" WHERE "TempTable"

Type of command but not to sure on the correct syntax and as everything is the same the use of wildcards for all fields

View 10 Replies View Related

Modules & VBA :: Updating Table Where Table Name Depends On Combo Box Value

Jan 17, 2014

I am trying to update a table with the value of a text box on the form where the table to update is as selected from a combo box on the form.I keep getting the following

Error message:
Run-time error 2465
Microsoft Access cant find the field & table_to_update & referred to in your expression..

But really can't see what I've done wrong. Have checked that the table_to_update string does contain the name of the table so guess it must be sql..

Code:
Private Sub Command91_Click()
Dim table_to_update, sql_string As String
table_to_update = Me.Combo49
Debug.Print table_to_update
sql_string = "UPDATE [" & table_to_update & "] SET [" & table_to_update & "].[Project] = """ & Text89.Value & """ WHERE [" & table_to_update & "].[ID] = " & Forms![T_entity]![" & table_to_update & "]![ID] & ""
db.Execute sql_string
End Sub

View 1 Replies View Related

Modules & VBA :: Use Criteria From A Table To Update A Category In Another Table

Jan 30, 2014

I have a table that has banking information in it (downloaded from the internet). I have a category field (lookup field) that I have to update manually so, for example, every time the electric bill is paid I have to click it and change the category to "electricity".

I want to set up a table with phrases for access to search for and a category to change to. For example if the banking table has "VIS ELECTRICITY 20812/773474868" and my search criteria table says anything with the word "electricity" should have category of "electricity", then I want Access to update the banking table based on that.

There will be several items in the search criteria table so Access will have to read through all of them to find the correct one. Is this possible?

View 5 Replies View Related

Modules & VBA :: Replace Values In One Table Based On 2nd Table

Jan 12, 2015

I have a table (tblConversions) that I'm using as a base for replacing values in a different table. tblConversions is set up as such and is made up of nearly 100 records:

ID LABEL CODE
1 Ashaway ASH
2 Barrington BAR
3 Bristol BRI
4 Jesse Smith BUR
....

Another table (tblSysItemLoc) has nearly 1,000 records with a field for Location Names such as Ashaway New Books, Ashaway Fiction, Ashaway Non-Fiction, Barrington DVDs, Barrington Reference, etc. Other fields in this table are just statistics.

What I need to do is loop through tblConversions, and find in tblSysItemLoc where the Location field Starts With the value from tblConversion.LABEL and replace the Entire field with the CODE. For example, from tblSysItemLoc "Ashaway New Books" gets changed to "ASH", "Barrington Reference" gets changed to "BAR", etc.

I feel like I need a loop inside of a loop, but I'm not sure where to begin. Loops are not my specialty.

View 10 Replies View Related

Modules & VBA :: Make New Table Using Fields From Another Table?

Jul 29, 2013

I have a table with 3 fields. The fields are down1, down2 and down3. . I would like to use this table to create a new table (downtime). What I need too do is loop through each record in the table and place the three fields independently in my new table. For example, I would like to go to the first record in my original table, than place down1 as my first record in my new table, down2 as my second record and down3 as my third. Than I will go to the second record in my original table and place down1 as my fourth record, down2 as my fifth record, down3 and my sixth record and so on. I want to make a toggle button that will do this.

View 7 Replies View Related

Modules & VBA :: Update Table From Another Table

Oct 20, 2013

I have 2 tables;

Compression and Compression_Import.

Table Compression is currently used to enter the load applied to the sample followed by a query that calculates the 'compression strength' using the entered load and the surface of the sample.

Table: Compression
.Labnr .,.... Load
13-142
13-142
13-142
13-142
13-142
13-142

What i would like to do is to import both the 'load' and 'compression strenght' from the machine.So i have managed to do an export on the machine (to Excel) and then made an import function which imports the content of the Excel file and puts it in a table called Compression_Import.

Table: Compression_Import
.Labnr .,.... Load........Compression strength
13-142.....11372..................64.3
13-142.....11376..................64.9
13-142.....11379..................65.3
13-142.....11343..................61.3
13-142.....11372..................64.3
13-142.....11371..................64.3

What i'd like to do is to update Compression.load with the value of Compression_import.load.I have tried several things like

Code:

UPDATE Compression_import INNER JOIN Compression ON Compression_Import.Labnr = Compression.labnr SET Compression.load = Compression_Import.[load];

But all it only seems to get the value of the last labnr from Compression Import and updates everything with it.

Result:

13-142.....11371
13-142.....11371
13-142.....11371
13-142.....11371
13-142.....11371
13-142.....11371

Is there a way of doing this using VBA? Or am i doing something wrong in the SQL statement?I have been trying to get this to work for a couple of hours, but after checking the internet for the last hour or so i can not get it to work at all..

View 3 Replies View Related

Modules & VBA :: Fill Table Using Another Table

Sep 19, 2013

I have a Table with employees from different departments and I created another form for their daily attendance details.

What i want is - if a director from department x needs to fill in attendance for all his employees, he just select his department from a combo box and all the employees under department x will be listed below and he can update the daily attendance.

This is what i have done so far - I have added a code but here the director will need to select his employees one on one which can be a hassel if he has many employees under his department.

I used below event procedures on date change
Me.TxtLastName.Value = Me.cboOperations.Column(1)

View 3 Replies View Related

Modules & VBA :: Copying From A Table To Another Table

Jun 12, 2014

I have two tables, table A and table B. Table A is a master table where it contains various values. I want to do it such that if user keyed in value X and value Y into Form B (linked to table B), it will check Table A for value X and value Y. If the values matched, it will display a new value (value Z) that is taken from Table A into Form B.

If IsNull(Me.txtValueX) Then
MsgBox "Please type Value X", vbInformation, "Value X Required"
Me.txtValueX.SetFocus
ElseIf IsNull(Me.txtValueY) Then
MsgBox "Please type Value Y", vbInformation, "Value Y Required"
Me.txtValueY.SetFocus

[Code]...

I am stuck at this part where i am not sure how to retrieve value C out.

View 5 Replies View Related

Modules & VBA :: Check If Data In Table 1 Matches With Any Of Data In Table 2

Dec 4, 2014

There are two tabs named Table1 and Table2. In actual there are two tables in Access database named Table1 and Table2. How the data is stored in ACcess tables, I have made two tabs in excel workbook. Now I want Access VBA code that will check if data in Reference field of Table1 matches with any of the data in Reference field of Table2.

If it matches then change the status of the corresponding record of Table2 with either "Withdrawn","Obsolete" or "Updated". SO it depends upon which field out of "WIthdrawn","Obsolete" and "Updated" in Table1 stores "Y". At a time only one of them will have "Y" and rest of two fields will have "N" as shown in the sheets.

As in the example, now Reference "R566" of Table1 matches with Table2 Reference so the status field in Table2 for that record will be "WithDrawn".

View 14 Replies View Related

Modules & VBA :: How To Get Last Inserted ID In A Table

Sep 10, 2013

I have this code in Access VBA and it is not working.

Private Sub btnAddWorkingday_Click()
Dim strSQL As String
Dim strDate As Integer
Dim lastID As Integer

strSQL = "INSERT INTO tblSchoolWorkingDays (CALENDAR_DATE) VALUES ('" & tBoxDateToAdd.Value & "'); SELECT @@IDENTITY AS LastID;"

DoCmd.RunSQL strSQL
End Sub

View 7 Replies View Related

Modules & VBA :: ID Into Multiple Table?

Jun 5, 2014

i have multiple tables all are connected 1 to 1 link the main field is autonumber field i want that if i enter id in one table it is added to other tables

View 9 Replies View Related

Modules & VBA :: Using A Table-name In A Query?

Dec 18, 2014

I am trying to create SQL within a sub that uses the sum of three elements in a table and the current date but I then want the name of the table that these entries relate to to be inserted into the table also so the Totals for a table called C5_1 would show in the table as:

BWS Date BASIC BONUS COMMISSION
C5_1 18/12/2014 2000 500 700

But there could be multiple tables and I am using a recordset to give me the lsit of tables. I just cant seem to get the SQL of the SELECT for the tablename to work.

Below is what I am currently using:

Code:
Dim db As Database
Dim rs As Recordset
Dim strSQLText As String
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblofC5_1Tables", dbOpenDynaset)
DoCmd.SetWarnings False

[code].....

There is currently only one TableName in the Table and that is C5_1

View 14 Replies View Related

Modules & VBA :: Copy Value To 2nd Table

Jun 18, 2014

I have a database with two tables, and a form that is bound to the 1st table. I have a duplicate record button on the form. One of the functions I want to happen is when the duplicate button is pressed, one value is copied from the form and added to the 2nd table. The tables are basically set up the same with an ID column which is the key and an autonumber, and the second value is a number. So I want to copy the number to the other table and add a record. What is the best method? Can I use an insert into and just copy from a variable, or is the better method with a recordset. Either way, I have not been able to figure this silly thing out and it is preventing me from moving forward with this database.

View 11 Replies View Related







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