It's been a while since I had to do anything with an Access Project so forgive me if this something easy.
I have an Access 2007 database which I have converted into an Access 2007 Project. I've created all the tables & views on a SQL 2008 server, granted all the necessary permissions and started testing.
Where I'm having trouble is, I have a form that is used to update data. The form is fed from a view (all tables in the view have primary keys) and view is schema bound. On the form for some of the fields I have a "Change" event handler which updates a "Last_Worked" field so we can track the last time those fields were changed. (the "Last_Worked" field is "datetime" in the SQL server) The event handlers are basically "Last_Worked = Now()".
The problem is, for those fields where I have a "Change" event handler, I can't put anything into those fields, I start typing and nothing is displayed in the field. When I check the "Last_Worked" field in table it's updating, but the fields I attempted to change from the form aren't changing.
I can update data and insert new records from a dataview so the view that is feeding the form is not read-only. If I remove the event handlers the problem goes away, but I need to log when those fields are updated. I've tried doing "Me!Last_Worked = Now()" and "Me!Last_Worked.Value = Now()" in the event handlers and get the same problem, I'm not able to update/edit those fields.
This worked perfectly in Access and I even created a blank Access database, copied the forms over, created linked tables to the views in the server and it worked. It just doesn't work as an Access Project.
Any help would be appreciated.
When you say event handler, do you mean you have set the control source? You cannot do that if you need the control for data entry. Note also that the change event runs for every small change. You can either use the default value for new records, or run some VBA in an update event of some relevant control. I reckon in this case you need:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.LastChanged = Now()
End Sub
Related
The issue I'm having is that many of the form controls trigger events that make changes to other fields bound to the form which results in a write conflict. I have tried placing If Me.Dirty Then Me.Dirty = False to save any changes from user interaction with the form, but I still receive the write conflict regardless or where it is placed.
For example, this will result in a write conflict:
Me!pnls_rte_profiles_id = Me!pr_rte
Me.Dirty = False
I'm using MS Access 2019 with a rather large database. The forms record set comes from 12 different tables linked through an ODBC connector. Each table has a primary key and a timestamp, but the timestamps aren't pulled as a part of the query for the recordset.
SOLVED:
So I found the issue stemmed from 2 places.
I forgot to include the other tables primary keys in my SELECT query.
Updating a records value to what it already was caused an issue with the MySQL ODBC connector.
The fix to 2:
Open the ODBC manager and configure the connector.
Under the Connection tab check Allow big result sets
Under the Cursors/Results tab check Return matched rows instead of affected rows
Relink tables in MS Access
Credit: here
Hopefully this helps others avoid days of struggling like I did.
I have inherited a MS Access DB (2007) which I am converting into a MySQL database. I have exported all the custom queries with no issues. But I cannot find the form INSERT query.
The DB has a form which contains sub-forms. There is one submit button which onclick validates the form and then calls acCmdSaveRecord which presumably inserts the record into the database.
Because the database schema is a moderately complex RDB I want to be able to view or export the INSERT query Access runs when saving a record so I can convert it to MySQL.
Is this possible and if so how would I do it?
You can't. That is done by Access behind the scene when using a bound form.
If you link the table from MySQL and bind your (sub)forms to the updated tables and views, the forms will still read and write your data.
I'm currently working on a form in access whose Record Source is supposed to be from a Temporary Table that should be generated at Form_Load() and deleted when the form is closed.
The way I have it working now is that the Record Source is set to another permanant table, and when the form loads, the temporary table is generated and the record source is changed. When the form is closed, the code sets the Record Source back to whatever it was originally. This works pretty well.
However, occassionally something goes wrong, and for one reason or another, the Record Source property doesn't get switched back, though the temp table is deleted so when I try to load the form, I get the error:
The record source 'TempTable' specified on this form or report does not exist
It turns out that this error occurs even before Form_Load() is called so I can't prepare for it before hand. The only way I can think of fixing this is trying to reset it when a button on my Home form is pressed, however this isn't optimal, since I still want to be able to open it from other locations.
Is there any way to catch this error and fix it without having to go into the form properties and change the record source any time something goes wrong?
Simple Workaround would be not to call/ Open the form but a function.
The Function would ba able to Arrange all recordsource work. Once this is done you can Open the form.
In fact you wouldn't need to switch the recorsource of the form anymore.
Function openform()
Prepare temporary table
Open Form
End Function
Martin
I am converting a Large MS Access 2010 application to act as a front end to MySQL 5.5 database, via the v5.1 ODBC Connector, and I am experiencing a strange problem when inserting new records with bound data forms.
In a data-entry form, if the default value of a date field is set in the properties of the control as a constant (such as #04-01-2014#) the new record is created in MySQL successfully, and after saving, all fields are visible in their associated bound fields. But if the default value is defined in the Access control as a function (example: =Date()) then although the MySQL row is created successfully, ODBC fails to find the new row and Access displays all values as #DELETED. Refresh and/or requery commands are not helpful. This is nothing to do with the well known issue of -- must have a primary key and a datestamp in MySQL. All of these safeguards are in place, and as stated, it does work without FE defaults.
No defaults are being set in the MySQL backend, and it makes no difference whether or not Nulls are allowed. Data type used in the backend is DateTime. If I do set defaults in the BE and none in the FE, everything is fine. But that way, the user DOES NOT SEE THE DEFAULTS in the data entry form... an unacceptable situation.
I have also tested both ODBC v5.2, and MySQL 5.6 with exactly the same results.
A solution that seems to work (so far) is to set all defaults in code, in the form.beforeUpdate event. Something like this:
form_beforeUpdate()
if me.newrecord then
field1.value = date()
field2.value = fOtherDate()
'etc
end if
'other code
exit sub
I could insert all new records with unbound forms and passthrough queries. But with 75,000 lines of code, that is a very big job
My question is - why do I need these "workarounds"? Isn't the whole purpose of ODBC to allow fairly normal operation? What is it about simple functions that "breaks it"? What other "ordinary" Access methods will break it? If I don't understand why it didn't work I can't be sure it is properly fixed.
Has anyone else had any experience with this SPECIFIC issue? I could not find any reference to it elsewhere. Thank you for your time.
So I've developed this Access 2007 application with about 2 forms, a lot of VBA code and a bunch of tables.
Now the business wants to run this off a network drive (call it G:\ for example). My current solution (which I've already implemented is have a table similar to:
__________________
|Setting | Value |
==================
Updating 1
UpdateBy User1
So let me give you a context. When the application runs there is a button called "update" which updates the local table from a remote server so we can apply filtering. Now when two people (user1, user2) launch the application, and one person clicks update then the updating field is set to true, and the updateby is set to their name.
So User number 2 tries to update, it checks if the updating field is true, if it is then it gives them a message (to user two, not to user one).
It works beautifully right now, but here is the problem: Lets say user1 is updating, and closes his program (or taskkills it) or the power disrupts, then the application shuts off with the updating field set to to true. Now no matter who launches it, they can not update because its "already updating"
Can you guys think of a solution to this? Maybe a workaround?
Consider a different locking strategy. In the click event of your "update" button, you can first open a recordset based on your tblUpdateStatus (the table where you've been writing UpdateBy) with dbDenyWrite + dbDenyRead options.
Set rst = db.OpenRecordset("tblUpdateStatus", _
dbOpenTable, dbDenyWrite + dbDenyRead)
Then do your other operations for the "update" button. Afterward, close and release the recordset ... which releases the tblUpdateStatus lock.
Trap the error when a user is unable to open the recordset (because another user has the table locked), give them a message to try later and exit your click event subroutine.
With this approach, when user1 locks tblUpdateStatus but exits Access uncleanly, her lock on tblUpdateStatus is released. You may not even need to update tblUpdateStatus unless you want to record which user has it locked.
See Create and Use Flexible AutoNumber Fields (from the Access Cookbook) for more details about using a recordset with dbDenyWrite + dbDenyRead.
Please do not run an Access application with more than one user when you have not split the database. It will cause endless trouble. The data portion (back-end) should be put on the server and the code and forms (front-end) should be put on each users desktop.
More information: http://support.microsoft.com/kb/162522
Read my article on why you split here:
http://www.members.shaw.ca/AlbertKallal/Articles/split/index.htm
In the above, I don't just tell you to do this, but I tell you WHY you split.
It should help you a lot in terms of users tripping over each other.