ALTER ms-access table that is locked - ms-access

I am trying to add a column to a table in an ms-access backend which is being used by multiple ms-access front-ends. When I try to add a column to the table like so (or with DAO):
sql = "ALTER Table MyTable " & _
"ADD COLUMN NewCol Integer "
CurrentDb.Execute (sql)
I get an error, and Access complains that the table is already locked by another user.
Is there a way to ALTER a locked table?
If you can't, how do you handle modifying a backend table that is always in use? Just wait until everyone goes home for the weekend? Are there some admin tricks that I can use to avoid this in the future?

Related

Trying to track changes in my MS Access Database

I have a table set up to track when people place an order (Order_Tbl). I duplicated the table that I call my order_change_log and added a date/time field (default value set to now). I have a one to many relationship between the orderID and order_change_logID. The idea is that before update, I want the existing data to be inserted into the change log table. I went into the before update field and made the following statement:
CurrentDB.Execute “INSERT into Order_Change_Log SELECT * FROM Order_Tbl WHERE ChangeLog_ID =“”” & Me.ID & “”””
I keep getting “Invalid Outside Procedure” and I’m getting frustrated… Not sure what I’m doing wrong.
What you want to do is called a trigger. In access a table's triggers can be accessed and created from the table's design mode via [Create Data Macros] on the ribbon. You are pretty much forced to use the macro language to create the trigger.
As an aside it looks like you are setting the default date in Order_Change_Log. Leave that default blank as it is not needed here and in many other cases leads to bugs.
In this case we will be using the after-update macro. The Before-Update values are available using [Old]
For an older example of a trigger happening after Delete see MS Access trigger?
Example Table and Relationships:
After Update Trigger Macro:
Use the ribbon to save the macro and you are done. change some values in the Order_Tbl then refresh or open the Order_Change_Log table to see the results

Modify linked SQL table name in Access 2013

I have a SQL table linked in Access. I'd like to know how to change the linked table object to reference a different table with the same design but another name. For example, I link Table1 and create forms with it, and now need to change it to Table2.
There doesn't seem to be an easy way to do this.
The table Description in Design View contains all the linked database and table information but it's not editable.
Using the Linked Table Manager, I can change the database the table comes from, but the tables in both databases need to have the same name.
I can create a query with Select * From Table1 and change it to Select * From Table2 to switch tables, but I don't want to use a workaround if I don't have to.
Remove the linked table, and use DoCmd.TransferDatabase to recreate the link with different names:
DoCmd.TransferDatabase acLink, "ODBC", your_ODBC_String, acTable, _
"schema.source_table", "target_table"
You can look up your_ODBC_String from existing linked tables.
Add the StoreLogin:=True parameter if needed.

How to add rows to a ODBC linked table in MS-access 2010

I have a MS-Access 2010 database that has Sybase tables linked to it through an ODBC named FNA.
I can read from the linked tables just fine, but writing to them is proving to be far more difficult. I am trying to use the below insert into sql to add data from an access table named _ModelVersion to the linked table named DBA__ModelVersion. Sometimes it works for a little while but mainly I get an error that says "ODBC--insert on a linked table 'DBA__Collectors' failed. authentication violation"
strQuery63 = "INSERT INTO [DBA__ModelVersion] ( ID, EDXVersion, template, DatVersion, DbVersion, AccessVersion ) " & _
"SELECT [_ModelVersion].ID, [_ModelVersion].EDXVersion,[_ModelVersion].ProjectTemplate, [_ModelVersion].DatVersion, [_ModelVersion].DbVersion, [_ModelVersion].AccessVersion " & _
"FROM _ModelVersion "
DoCmd.SetWarnings False
DoCmd.RunSQL strQuery63
DoCmd.SetWarnings True
Should some other method be used? Not sure it matters but I have combo boxes that use the linked table as a source and before this query is run a dmax function is used on the linked table in question as well. I read that creating a stored procedure on the sybase database side and calling it from access would be the way to go but I have no idea how to do that, much less get the stored procedure to pull data using the FNA on the Access side.
Edit: So far I have tried:
1) making sure data types from sybase are being shown in access properly (data types in sybase are numberic and varchar and in access they show up as decimal and text which seems to be fine)
2) Adding autoincrement primary key to sybase table and indicating it when linking it into access
3) using currentdb.execute with dbseechanges
4) refreshing the table using the method shown in the accepted answer here
5) Tried adding a field timestamp with the value set to current timestamp. No improvement.
Funcionallity remains the same: The update query will occassionally work, then continue giving "run-time error '3155': ODBC--insert on a linked table failed" which is seen whether I use VBA or query design to run the query.
I've experienced some issues in the past with RunSQL on ODBC linked tables. When dealing with a linked table with a Primary Key, you need to use the dbSeeChanges option.
The error you mention above indicates a table with no primary key set. Right click the table and enter Design view (in MSAccess). Highlight the row you wish to make Primary Key (Unique Identifier). Click the button with the gold key icon.
Try UPDATE/INSERT with the following...
CurrentDb.Execute "INSERT INTO tblYourTableName VALUES ('YourTextValue',123)", dbSeeChanges
Substitute your table/columns/values.

Add mysql table column dynamically

How to add table column in mysql Dynamically?
I have a vb6 code and mysql as database.
Suppose I want to enter new column in the textbox then the value of textbox will be a column in mysql.
Is this possible? How to achieve this one?
See ALTER TABLE command for that.
But normally it is not a great idea to alter DB structure from your client application.
If you have to, this means that your DB is not very well designed.
You can always have a dynamic data structure presented in your statically structured DB tables set by using relationships between tables.
Yes its possible
Query for adding a new column to database is
"ALTER TABLE mytable ADD COLUMN " + textbox.Text + " VARCHAR(40)"
From VB you can use ADO for it

Remove link for linked table in access

Had created a linked table in MS ACCESS 97. Need to remove the link and make the table static so that, even if the data in backend db is removed or altered, this should not affect the table data in MS Access.
Use a "make table" sql query in order to get the data into a local table then you can delete your linked table, SQL something like:
SELECT * INTO LocalTable FROM LinkedTable