Programmatically Archive Access Backend Tables - sql

I have an Access application that is now split into front end and back end databases. I would like the user to periodically archive the data from the back end tables to improve the database performance. What I have in mind is the following:
Create a new empty database file
Create empty copies of selected tables from original backend database
Insert data from original backend database to the new database tables with certain criteria, for example date range
Delete from original backend database tables the archived data
Can I achieve this programmatically so the user only needs to perform simple actions like clicking a button and input the data range?
I am using Access 2003 for my application.
Thanks in advance for the help.

Concerning your Boolean field, if it bothers you seeing the -1 and 0, just open the table in design view, select your Boolean field, then in the properties for 'Format', just either double-click to scroll thru the options or click the drop-down arrow to select the desired format.
It will then display as either 'True/False' or 'Yes/No' or 'On/Off'

Related

How to change the index property of a linked table field Access ACCDB with VBA

Basically, my access database is split into frontend and backend. I am using the backend database as a linked table. In one click event I want to change the index property of the linked table field, but to change the field property of the linked table from the front end it says "Design can not be modified, you must do it in the source database". How can I do this with VBA?
Thanks in advance

VBA to send a SQL string to a Tableau Connection

I have an excel work book that allows users to update multiple SQL statements at once based on data entered into cells.
Then the users copy the updated SQL and go into Tableau and paste it into the corresponding custom SQL data source in tableau and refresh it.
Is there a way to send the updated SQL code directly to the corresponding connection in Tableau?
If the table name is changing, that presents a challenge.
I have two suggestions.
Modify the twb xml.
A Tableau workbook file is simply an XML file. One part of the xml contains the connection information, including your custom SQL. VBA has some libraries for manipulating XML. You can write some custom VBA code to modify the XML that contains the custom SQL.
Use VBA to create/alter a view in teradata
Teradata allows database views. With VBA, you can connect to teradata and create/alter a view that changes based on your parameters from Excel. The key is to keep the view name constant, then Tableau will not need to be changed each time the underlying view definition is changed.
Of the two, my first choice would be the second option. It's cleaner and doesn't require distributing a new workbook file each time.

How to connect an Excel file to an Access Database

I have created a query in an Access database and exported the query result into an Excel file. Now, I want to connect that Excel file to the Access database (or to that query) so that whenever some fields are updated in database, those changes would be automatically updated in the exported Excel file (report). What would be the best way to do it?
Thanks
You can create a link between Excel and an Access table or query by going to the Data tab on Excel and clicking the "From Access" icon.
Alternatively if there is a trigger inside access that you can use to update data (or if you don't need real time updates just hourly or daily ones), you could have access programmatically re-export.
If you want to work with data in Access, but still maintain the data in Excel, you need to link to the data rather than import it. Follow these steps:
Create a blank database or open an existing file in Access.
Select File, Get External Data, Link Tables.
Select Microsoft Excel as the file type.
Select a worksheet or named range to import, and then
click Next. You can import only one worksheet or named range at a
time, and each one will become an Access table.
In the next dialog box, select or deselect the check box First Row
Contains Column Headings, depending on whether your worksheet has
headings. Then click Next.
Enter a name for the table (or accept the default name that Access
suggests), click Finish, and click OK.
Now you have an Access table that looks almost exactly like the imported table. The advantage is that it maintains a live link to the Excel worksheet and can be edited in either application.

Calling a subroutine as part of a SQL Transaction

My project is an orders application, where users can enter orders from different customers, using an UltraGrid to enter and edit data. When the Delete key is pressed on the keyboard, it prompts a MsgBox for the user to confirm they want to delete the selected row, and if so, it runs a DELETE query to delete that row from the database.
I also have a Save button to allow the user to save the order/changes made to the order. Ideally, I only want the row in the grid to delete temporarily as, if the user then doesn't save the order, the order line shouldn't be deleted permanently from the database.
If I put the DELETE query into a separate subroutine, can I then call this subroutine from my class that is saving it as part of the transaction?
This seems like it isn't going to work, as I'd not only need to call the query, but also somehow store the deleted row somewhere temporarily so that it knows which data to delete in the transaction, as well as a Boolean variable to tell it whether there is even any data to delete...
Are there any simpler ways of doing this? Would the above way even work?
Sorted it... Nothing actually complex required at all, just needed to change the code, as below:
Try
Dim Dc As New OleDbCommand
Dim rowcode As String = ""
rowcode = dr.Item("Product_Code").Value
Changed to:
Try
Dim Dc As New OleDbCommand
Dim rowcode As String = ""
rowcode = dr.Item("Product_Code", DataRowVersion.Original)
Simplest way of doing it, is keeping all of your changes in-memory (additions, modifications and deletions) and then synchronizing them to the database when you hit your Save button.
Possibly, you'll need an AJAX action to add the operation to the server-side and a client-side script to update the row on the grid.
Grid does not work with back-end database. It is only dealing with its local DataSource. So when you save the data back to your database check for deleted rows and preserve them.
If you want to update the local data source only on save button click you can set the grid's UpdateMode to OnUpdate. Then you will need to call grid's UpdateData method. Again, this will update your local data source. How and when the local data source will update the back-end database has nothing in common with the grid. So depending on the type of your local data source you will need to handle checking for deleted rows before you send updated data back to database.

How to copy all the data from a table in Sql Server 2008 to file

I have created a table in sql server 2008 and the table contains a lots of records.I need to get all the data from that table to a script file.
If you have SSMS;
Right click on your database
Generate scripts
Change radio button to Select specific database objects
Check the tables box
Select your table
Next
Set the filename etc
Click on Advanced button
Change the Types of data to script setting to Schema and data
Click next to finish
Blog post here with screenshots for clarification