Hi I have a table that is simply a copy of another table on another sheet on my workbook.
The second table is generated using
DATA -> Existing Connections-> and then I select the Table tab.
Usually this work really well but in some cases (not always) the new table has the rows in a different order from the original one. How is it possible to avoid this?
Related
I want to be able to upload new records into a BigQuery table from Google Sheets. I know how to attach them through Connected Sheets, and have the table mirror the Sheet, however I don't want it to mirror the sheet exactly, I want to be able to upload the sheet into the BigQuery table, and then clear the sheet without it deleting the table. Is there a way to do that through Connected Sheets, or do I need a script to do that.
Thanks.
Everything I find on the topic only shows how to make a table from scratch in BigQuery, and have it mirroring a Google Sheet. This doesn't fit my application because my sheet will get too big if I keep all the records around , too quickly. I want to be able upload the records on a sheet into a database, then clear the sheet without it affecting the database.
If you want to keep everything in BigQuery, and you want to work with exactly one Sheet, I think a saved query using the BigQuery DML (data manipulation language) would be the way to go.
Let's imagine that you have a Google Sheet that you've added to BigQuery as an external table called my_gsheet in a dataset called external. For the sake of argument let's say it has three columns, id, name, and created_at.
We are going to use an insert select statement to append this to a table called all_records in a dataset called big_data, like this:
INSERT
big_data.all_records
(id, name, created_at)
SELECT
id, name, created_at
FROM
external.my_gsheet
Now you can save this query and run it whenever you want to bring the latest spreadsheet-based data into your warehouse table.
The table big_data.all_records should be created by you in advance; if it's going to be very large you should probably think about making it a partitioned table, and if it's going to be queried a lot you may want to cluster certain columns too.
You could even schedule the query to be run regularly, although beware: if you run the query above multiple times, duplicate rows will be created. If you have a unique identifier (e.g. the id column for my record), this can be avoided with a MERGE:
MERGE INTO
big_data.all_records AS target
USING
external.my_gsheet AS sheet
ON
target.id = sheet.id
WHEN
NOT MATCHED
THEN
INSERT (id, name, created_at)
VALUES(id, name, created_at)
This query, unlike the previous one, will only insert rows if they have an id that doesn't already exist in the table. If the id does exist, it will do nothing (you could add a WHEN MATCHED THEN UPDATE clause if you want the ability to overwrite instead).
I have an old dbase-database (made with a program programmed with clipper 5.2) which consists of multiple tables (files). The tables are linked with some sort of recordnumber, but in the source table, no recordnumber-field is found. I want to convert this database to Access and re-establish the links. I've read something about a dbf recordpointer (?) but i don't know how to extract it from the DBF.
Well, if recno() or some such is being used, then it suggests that the table starts at one.
Remember, you can’t update a PK autonumber in Access, BUT YOU CAN RUN append queries against such tables!!!
So link to a dBase table. When you view this table in Access does it show that incrementing column?
It should and does for me.
The above detail has not been made clear by you.
So let’s assume you see this column that increments and is NOT marked as a PK?
That is just fine (and is expected). As LONG as you see the incrementing number in that linked table then you are just fine.
This process of importing then becomes rather fast and easy.
On the create ribbon tab, just choose query design.
Drop in that linked table.
From ribbon choose make table. Enter your new local table name.
Drag the * from the table into the into the query grid (first column of grid).
You have this:
Now run the above query query (hit the run button in ribbon).
Exit (toss that query out – no need to save).
The result will be a new local table, with that number column.
Now, empty data from that local table.
(Ctrl-g to debug window)
Currentdb.execute "delete * from NewLocalTable"
Now do a compact + repair (this re-sets any autonumber columns in empty tables – might not be required – but just do it anyway). And it reclaims the empty space for that table we just emptied out.
Ok, now open that new local table in design mode. Select that first number id column, and delete it. (click on that row - likely first row - hit del key).
Now, click on first row to select the column that is first. Hit insert key to push it all down, and enter the name of the numbering column you JUST deleted. Tab key, autonumber, and then from ribbon whack the PK button (primary key button).
Close table designer. Save the design changes.
We now have an empty table with a PK autonumber column as the SAME name as what we had before.
Now, create new query, droop in linked table.
From ribbon choose append query, and enter name of new local empty table.
Drag the * into the query grid.
Run it.
We now have a local table, with PK autonumber, and the columns will match up to the linked table.
For a 10 second test?
Ctrl-g (jump to debug window).
Type in:
? dcount("*","linkeddBaseTabble name")
? dcount("*","NewlocalTable name")
The record counts should be the same.
At this point you have a local table with same columns + the PK ID autonumber column.
You can repeat the above over and over. It goes fast. 20-30 tables will not take long.
The result is now local tables, and each table will have an autonumber PK column with the same column name.
I would think the column as a linked table is “ID”, but it might be RECNO. (So use that for the local PK column names).
So you:
Link to dbase table.
Query builder – make table.
Ctrl-g to empty local table:
Currentdb.execute "delete * from local table name"
Open local table in desing - delete number column, add it back as PK autonumber.
Query builder, drop in linked table. From ribbon select append query, enter name of local table.
Drag “*” to query grid – run it.
You now have a local table, with PK autonumber same as linked table.
Move on to next table to import (add an autonumber to each table you import with above few steps.
You could just import the tables in Access...and work your way using them as blueprint.
Just ensure that the "table relations" are correct... i know that there isn't one but take the "logical" path...if you a table with a fieldName "FaxBookID" and you have a table "FaxBook" ...you know they are related
I'm a Windows Access newbie. However, I have to make some changes to our database at work.
I've created a new list of records with Excel, sorted as follows:
101A
102A
102.01A
102.02A
102.03A
103A
103.01A
...
When I copy & paste it in my access table, MS Access 2007 keeps my custom order until I restart the program. When I reopen it, the table gets sorted this way:
101A
102.01A
102.02A
102.03A
102A
103.01A
103A
...
How can I avoid this? Is there a way to "lock" my custom order when pasting from Excel to Access?
These records are being shown in a dropdown menu. but I'm not able to "code" in Access, I just have to change these table records by pasting them in the exact order I've established in my Excel table.
A database doesn't work like an Excel sheet.
If you select rows from a table (either opening the table directly, or using it as row source for a dropdown box), the rows are always returned in a certain order.
If you don't specify the order (ORDER BY ... clause), the primary key determines the order. In your case, this data column is probably the primary key.
And since . is sorted before letters (see Ascii table), you get the result you see.
To avoid that, you would need an additional column, e.g. "Sortnumber", where you can define the sorting you want, and use in a ORDER BY clause.
Yes, I solved creating an ID column and setting it as primary in the ORDER BY ... clause. Thanks.
I am new to access and I was wondering how i can only copy the headers from access to excel. There is too much data in the access table and I only need the headers. Thanks!
Filter your table so it doesn't show any data (e.g. right-click in a text column and filter for "Equals: qwerqwerqwer". Then you can copy&paste the empty table.
As pointed out by Wayne (thanks!), this doesn't actually work - Access doesn't copy an empty table.
You need to have at least one record, so the best method is to right-click into the primary key column of any row, and choose Equals <the current value>. This will leave you with one record, now you can Ctrl+A to select all and Ctrl+C to copy.
Create a query for the table that selects all columns, but filters on a unique value for one row. Below is a sample query that will return one row of data with headers. If you dislike the one row, then I think you will be writing some VBA code to get the field names.
SELECT tblLog.eDate, tblLog.eTime, tblLog.Form,
tblLog.User, tblLog.Detail, tblLog.ID
FROM tblLog
WHERE (((tblLog.ID)=1));
You could possibly select all the fields one at a time from the Fields collection of a table, write that to an array and export the array to an Excel spreadsheet.
Or, you could create a new query, go into the SQL view and write:
SELECT Top 1 *
FROM MyTableName
It will give you only the first record of the table. Copy/Paste as text that to an Excel spreadsheet and delete the first row. Voila!
As it stands, I am currently looking to import data from an Excel spreadsheet into a table on a monthly basis. The header row in the spreadsheet contains the date that the original query was run.
I have one master table in access consisiting of multiple files. I would like to set up an automated process to capture the date in the header upon import, and then record it in a field for every new record that was imported.
There are two caveats here:
Spreadsheet sizes will vary depending on where data exists.
I have no control over how the data is provided. Fields that contain no data for the month will not populate to the spreadsheet.
Less frequently fields will be added that do not exist.
So far I have been identifying these new additions manually and creating a new field for them at the end of the field list. I realize that this is very inefficient and I would like to automate it, if I can.
Does anyone have any insight? Any assistance would be greatly appreciated.
OK, here's the steps you'll want to take.
Create a link from Access to your Excel spreadsheet. Access will now see this as a table.
Create a make table query using the Excel table as the source and adding the date (derived from a sub-query) as an additional field.
Then run the query. This will automatically create all the fields.
If, however, you need to create new fields in an existing table, then you'll have to use VBA, read each header in the Excel table, compare it to the schema of the existing table, and execute an alter table query to add the field.
Good luck