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 Replies


ADVERTISEMENT

Cross Referencing Records From A Single Table

Sep 22, 2005

I tried the idea sugested in post (http://www.access-programmers.co.uk/forums/showthread.php?p=423080#post423080) but it didn't seem to give the cross referencing that I had hoped for .... example 1 is related to 4,3, and 5 while 6 is related to 1 thus implying an extended relationship to 4,3, and 5.

In a standard one-to-many I'd look at record 1 and see that it is related to 4,3,5 but if I were to look at record 6 I'd only see that it is related to 1. How would I set up the table relationships to drill further to see that 1 is also related to 4,3,5?

How do you do a many-to-many from one table back to that same table?

tblEvent
EventID(AutoNumber) EventTitle(Memo)
1 memo content
2 data
3 more memo content
4 some info
5 more stuff
6 other text

tblEventRelationships
EventParrent EventChild
1 4
1 3
1 5
6 1
3 2

In addition ... how would one set up the integrity to prevent loops from forming?

View 6 Replies View Related

Modules & VBA :: Public Function With Variables Referencing Table Date Fields

May 31, 2014

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

View 5 Replies View Related

Modules & VBA :: Automatic Database Table / Fields / Records Count

Apr 9, 2014

the project I have comprises four seperate databases all linked but kept apart for logic and data reasons. I must have rapidly approaching 300k records across all of them. As a result I am trying to extract on a regular basis (monthly) the dimensions of each database. Specifically, I want to be able to produce for each database;The number of tables (I have two types data and reference, it would be nice to be able to split the result).The number of fields per table.The number of records per tableI am not really interested at this point about other database objects, such as queries or reports.

View 11 Replies View Related

General :: Combo Box Referencing One Table - Inputting Value From Different Table

Jul 11, 2013

I am trying to use a combo box to select the Company in an input record form for my Transactions. In the Transaction table, each record contains the Company ID, but not the company name (I have a relationship with a Company ID primary key in a separate table that has all the companies information).

I would like to be able to select the proper company in the combo box and have the form save the value as the Company ID number with the rest of the input data in a record (it will then refer to the correct company name in the other table if I query it because of the ID key).

View 3 Replies View Related

Modules & VBA :: Referencing All Records In Subform

Feb 23, 2015

I am trying to add a save/close button to a form that will only close if certain conditions are met and if they arnt then display a message box.I got the basics on how to save and close the form, do a simple if statement and display the message I want but the problem im running into is my subform can have multiple records and of those records each records status is set by 3 different checkboxes. I need all of those records status to be same when the form is closed.

if I do an if statement like

If Me!frmDataform1subform.Form!StatusID.Value = 1 then
docmd....

then all it looks at is the first record, how do I get my if statement to look at all the records in the subform?

View 2 Replies View Related

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 :: 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 :: 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 :: 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

Question On Table Referencing A Table.

Oct 12, 2006

Howdy all,

I am trying to build a db to track all the different projects I do on my web shop www.mutzigcreations.com (http://www.mutzigcreations.com). One thing I need to do is to be able to track the different materials I make things from. This wouldn't be to bad, but sometimes I use several different materials in one project and for the life of me I can't figure out how to do a table system (or form for that matter) that would let me do this.

I build out of woods, acrylics, and other special materials so I have a table for each of the 3 main types. Then I created tables called Material-1, Material-2, etc..that did table lookups to the 3 main type tables. These tables (material-1, etc..) are then related to my main table called Creations. (is this the correct way to go about it? as I can't seem to get it to work at all)

I would eventually like to set up a form that would have a check box next to Material-1, Material-2, etc...that would enable me to select:

A. if more than one material was used
B. What the materials were.

I didn't want to make several copies of the 3 main tables (wood, acyrilcs, special) as that seemed counter productive since the same info is used for each of the different material-1, material-2 selections.

Can anyone help me figure out what do to, or the best way to do it?

Thank you!
Doug

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

Referencing Another Table Via Drop Down

Jan 11, 2007

Hi all,

have used the wizard to take values for a table dropdown field from another table

the table has

surname forename and class all of which reside in another table... ive tried to set up the bound columns so when you select a surname from the drop down the other two fileds also referencing that 6able are automatically filled in with their corresponding values.

so if the ref table had

smith john 1m

by selecting smith in the new tables drop down, the forename and class fields automatically select the corresponding values from the ref table..

im sure this is possible but cant get it to work and cant find anything on the web (although this is probably down to not knoing the right search string)

any ideas?

dubs

View 5 Replies View Related

Self-Referencing Table Question

Jul 6, 2007

Having (with much help from many of the experts here) overcome the hurdles of junction tables, subform to subform movements, and the seemingly easy design issues of a form, I have now created a self-referencing table. I humbly return to ask for advice from those experienced with these relationships...

I have been led to this in order to load in to my DB a certain class of documents, linking them relationally to their parent documents, while performing the data input for both into the same form. What I have done and what the problem is are as follows:

I created a new field in my form (formDoc), "LinkedExhibit". In the relationship window, I reloaded the Document table and reestablished all prior relationos, then added a second (alias) table Documents1, linking the primary key of this alias to the LinkedExhibits field.

I have the Linked Exh field set up as a combobox linked to DocTitle from the Documents table ONLY for the purpose of saving keystrokes if a duplicate should arise.

Unfortunately, when I enter a new document and then continue entering data through the LinkedExhibit field, and save by moving on to another subform related to these, the Documents table shows all of what I typed, except it shows the Linked Exhibit saved as DocTitle, and the DocTitle that I had typed is gone...

I really am flying blind but believe the alias table is not linked right, or I am using that concept to do something it cannot do...

I am attaching the DB, in Access2007, if someone could lend an eye to it...
I would appreciate that.

View 14 Replies View Related

Referencing To Users Collection For A User Table Possible?

Jul 27, 2007

My search was snowballed with lot of results about dealing with split database, seeing who's online, etc. so I'm not sure if that is a good idea.

I want to make a table of Users because my users may need to put their name on some of reports, so I could use CurrentUser() to figure out who's who and put down their proper name after comparing the username via a query.

However, I'm not sure if it's possible for me to link the user table to the user groups of database to ensure that there's no ghosts or users that doesn't have a proper name to be placed on the reports or whatever. More of a validation, really.

Is that doable or maybe there's another way to do that?

Thanks!

View 2 Replies View Related

Modules & VBA :: Delete Records From A Table Based On Records In Another

Feb 7, 2014

I have a table InvPrice and Updated Pricing

Need to delete all records from InvPrice that Match UpdatedPricing

InvPrice.StockCode = UpdatedPricing.StockCode
InvPrice.PriceCode = UpdatedPricing.StockCode

I have tried something like this...

Dim dbs As DAO.Database, sql As String, rCount As Integer
Set dbs = CurrentDb
sql = "DELETE * dbo_InvPrice Inner Join (dbo_InvPrice Inner Join UpdatedPricing on dbo_InvPrice.StockCode = UpdatedPricing.StockCode ) ON on dbo_INvPrice.PriceCode = UpdatedPricing.PriceCode "
dbs.Execute sql, dbFailOnError

View 14 Replies View Related

Queries :: Select All Dates Since A Given Date Without Referencing A Table? (Access 2007)

Apr 23, 2014

Is it possible to create a query to select all dates from a given reference date? I don't mean all dates in a table - I mean all dates generally?

(The idea being to fill the first field in the resultant dataset with the list of dates, then run subqueries off that to fill the remaining calculated fields)

I'm currently using a date field in one of my tables to populate this first field (the full SQL is in a separate thread here)

But that was just a convenient way of getting a list of dates; the dates in that table don't actually have any significance to the resulting dataset (other than they should roughly overlap with the dates I'm looking for)

The flaw in that method is that the table from which I get those dates can only ever have dates up to and including yesterday. I also need to get today's date in there (and calculate the subqueries based on that date as well).

It's also possible - although unlikely - that there could be random dates missing from that table as well - in which case I need to plug those gaps and calculate my fields for those missing dates as well.

For clarity; that first field (AsOfDate) should contain every weekday from the earliest date in that table (i.e. Min([tblBalances].[BalanceDate]) up to and including today. It doesn't matter if any of the dates inbetween are missing from tblBalances as the subqueries will just return zeroes for those dates (which is exactly what I want to see).

View 3 Replies View Related

Access 2010 - Main Menu Needs Drop Down Box Referencing A Table For SEARCH

May 6, 2014

I have a main menu "MainMenuF" in my database and I would like the database to be able to be searched by any of the column headings. For example I have a table titled "NewLabReportT" this table has many column headings like "Submitted By" "Reviewed By" "Title" "Abstract" etc...

I would like my users to be able to click a radio button with the same column headers on this main menu and have a box that pops up to say "Enter search parameter" and have that parameter be searched in the table "NewLabReportT" and generate a FORM not a REPORT of all of the listings in the database that have that keyword associated to that certain category searched. That way they can "CLICK" the exact field they are looking for and have it open right up to that form.

View 2 Replies View Related

Forms :: How To Save Records To A Table Of Web Database

Mar 5, 2014

I'm using Access 2010 and now trying to save a selected record to another table which I have no clue where to find the "Code Builder" to put my code on after spending hours and hours, I managed to create a form, but couldn't figure out where to save this data.

All I need is to put this line
"INSERT INTO ResultTable (StudentID, CourseID, PaidID, Comments) VALUES (" & cboStudentSelect & ", " & cboCourseSelect & ", " & cboPaymentSelect & ", " & txtComments & ") WHERE StudentID = cboStudentSelect

Perhaps, the new Access 2010 doesn't use this or something new that I couldn't it.

Attached is the file.

View 2 Replies View Related

Modules & VBA :: How To Sum Up Records In A Table

Mar 17, 2014

I want to sum up specific records in a table called TNS.

All records with Division = Common should be summed up to

the records with Division = AK.

TNS contaıns columns Division, 012013,022013...,122013

I tried following without success:

Code:

Public Sub TEST22()
Dim strSQL As String
strSQL = "Update TNS Set [012013] = 0.5 * DLookup([012013], TNS, Division = 'COMMON') " & _" Where Division IN ('AK') "
DoCmd.RunSQL strSQL
End Sub

It shows me following error:nAccess doesn't recognize TNS as a valid field name or expression. Something is missing in this syntax.

View 3 Replies View Related

Modules & VBA :: How To Insert Records Into A Table

Dec 9, 2014

I am reading through a table looking for duplicate values in the FullName text field. I want to store in a new table the duplicate records I find, storing just the MemberNumber and the FullName. When the VBA code runs and finds duplicates, the SQL statement to insert a new record into the Duplicates table asks for the value of LastMemberNumber and LastFullName when it already has the values and has displayed them in the message boxes! What am I doing wrong?

The code is:

Private Sub Command0_Click()
Dim rs As DAO.Recordset
Dim dbs As Database
Dim LastMemberNumber As Integer
Dim LastFullName As String

[code]....

View 7 Replies View Related

Modules & VBA :: Copy Records To 2nd Table

Mar 28, 2014

I'm getting myself into a bit of a muddle.

I have four tables:
tblinvoice / tblinvparts
tblquotes / tblquoteparts

when I open the tblinvoice form it has tblinvparts as a subform. tblinvoice has a listbox that lists quote numbers linked to vehiclereg. I have a button on the tblinvoice that will open a popup tblquoteparts continuous form linked to the quoteid on tblinvoice. These filtered records have a select button so I can select all or some.

I have now got stuck as I need a button on tblquoteparts popup that will copy the selected records from tblquoteparts and paste them into tblinvparts where quote (on tblequoteparts)=quoteid in tblinvoice.

In a nutshell, I would like to copy selected records from tblquoteparts to tblinvparts.I need to duplicate the records because only 10% of invoices are generated from a quote and the quote parts/prices may differ from the final invoice.

View 9 Replies View Related

Modules & VBA :: Find Records In A Table?

Aug 23, 2013

I have a database for work where I have a table of meters and a table of Faults which has a list of all faulty meters at one time. When a fault is repaired, I have a macro which updates the Meter Status to Working, adds a Fault Closed date, appends the record to the Closed table and then deletes it from the Faults table.

The user runs this from a form by clicking the Closed Fault button which activates the macro. I've added Echo on and off to hide that the form is temporarily closed while the Append and Delete queries are run and then it is re-opened again.

My problem is that the Form always opens at the first record in the Faults table. I would like it to open to the record which would have been next after the one that has been moved to the Closed Faults table.

Below is the code I have been using to test the Copying Meter Reference, closing and opening of the form and finding the correct record:-

Function CopyTest()
On Error GoTo CopyTest_Err
Dim strMeterRef As String
DoCmd.SetWarnings False
DoCmd.GoToRecord , "", acNext
strMeterRef = Meter_Reference

[code]....

As you can see I am trying to go to the next record, copy the Meter_Reference by setting it to strMeterRef and then Find strMeterRef when the Faults form is re-opened.

I have a Macro embedded in a button which calls the above Function by using RunCode but nothing happens.

View 2 Replies View Related

Modules & VBA :: Export Table From A Different Database To Excel

Jan 31, 2014

I have 2 databases, mymacros.mdb and otherdb.mdb

I am writing some vba code in mymacros.mdb to try and export a table from otherdb to excel. I do this becuase there is a new copy of otherdb created on a daily basis.

I have tried using docmd.output and docmd.transferspreadsheet to achieve this but dont know how to specify that the table I am exporting is in the otherdb.mdb file.

View 5 Replies View Related

Modules & VBA :: Adding Table To Back End Of Database

Feb 27, 2015

Can I create a table in the back end of my database using VBA in the front end? My client is using this system and I can't easily go to their location. I need to create a table on the back end and have it available in the front end applications. My thought is to create a front end only for the purpose of updating the backend with this new table. My idea is now to have it open with a button for the user to click - this will add the table to the backend with the required fields, confirm the update was completed and then close. This app then would be trashed so it would not be run again. (Though I would put a check in the VBA that if the table existed, the user would get a message box and the coding stopped to avoid overwriting the existing file.)

And once the table is created, is there a way to programmatically link it to the front end. I will be providing a new front end with this update so I could add something in the new version.

View 10 Replies View Related

Modules & VBA :: Export Link Table To Another Database

Apr 22, 2014

I want to export my data in "Asset_Table" link table to another file store in "d:Database1.accdb" with table name "AssetList". The Code i used as below. But when i opening the "Database1" file, the Table "Assetlist" is a LINK table type (I want Local Table). How to export the Link table data to Local Table data on another Database file.

<<<<<<<<<<<<<<<<<<<<<<
Private Sub Copy_Click()
DoCmd.TransferDatabase transfertype:=acExport, _
databasetype:="Microsoft Access", _
databasename:="d:Database1.accdb", _
ObjectType:=ACTable, Source:="Asset_Table", _
Destination:="AssetList", structureonly:=False
End Sub
<<<<<<<<<<<<<<<<<<<

View 1 Replies View Related







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