Microsoft Access 2013 VBA code changes bound control on change of record am getting write conflict - ms-access-2013

Have just got back into coding in Microsoft Access, so it might be something stupid.
Situation:
Sqlite database linked to Access db via ODBC.
Have created a form which has bound controls from a table.
Due to the way sqlite stores dates, as text, I am not able to use the calendar picker. I thought easy I can create an unbound text box control, set the format to date and then I will have a date picker. Then in VBA just get it to change the value of the bound date control, which would be hidden.
Me.txt_Date_of_birth.Value = Format(Me.Txtdate_of_birth_with_calandar_control.Text, global_date_format)
It works it changes the value of the bound control (which for testing is not hidden).
But when I change records I am getting an error of
Write conflict. This record has been changed by another user since you
started editing it. If you save the record, you will overwrite the
changes the other user made.
From my testing it is being caused by this unbound control updating the bound control. Anyone know a simple fix?
And I would prefer not to get my data from a query that formats the text field into a date field.
And I can confirm that the error does not occur when I create an access table and try to update a bound control.

Try saving the record at once:
Me.txt_Date_of_birth.Value = Format(Me.Txtdate_of_birth_with_calandar_control.Text, global_date_format)
Me.Dirty = False

Does this table have a primary key? - in the eyes of Access - by which I mean when you look at the table in design view with Access.....
If not try adding that.

Related

Microsoft Access unable to display image attachment (Runtime Error 2220)

I have a table called "Subsidiary Companies" where I store the names of different subsidiary companies and their corresponding company logo images as an attachment in a table.
I have a form called "invoice" where I use it to generate invoices. Whenever I select a subsidiary from a Combobox, it will change the image attachment box on my form to the one corresponding to the company selected.
After I attach the image to the table it worked. When I closed my entire access program and went back to it, it doesn't work anymore even though I did not change any codes, settings or image path. I got an error instead, "Runtime Error 2220: Microsoft Access can't open the file image.jpeg".
Here is my code to select the attachment image based on the company selected:
Me.AttachmentCompanyLogo.DefaultPicture = Me.ComboboxCompanySelection.Column(1)
Not sure where it went wrong as I am not very familiar with Access, would appreciate some help, thank you :)
based on this statement: " When I closed my entire access program and went back to it, it doesn't work anymore"
that behavior would occur if you failed to also include the primary/foreign key cross reference value in the record. such that when you next go to select it - it can't be found because when you added the image/path it also needed the key value as a cross reference...
this is just a guess of course...
look directly at the table and see if this data is missing...
on a different topic; if you have only a small quantity of images the use of attachments is ok however if there will be a larger quantity then one should not use the attachments feature and instead store the image docs in a separate folder while putting the path to the image doc in a table.

Saving copy of old table entry to another table when updating table entry with SaveChanges()?

Im working on an online store project where I have already made it possible for an administrator to update different table entries via the store gui (like items, user profiles, orders etc). SaveChanges(); is used to save the changes.
Im currently trying to figure out how to make this work:
An entry in table "items" gets updated.
Before the entry in the table "items" gets updated, a copy of the old entry gets saved into a table named "history-items".
The copy that is saved to "history-items" preferably has a timestamp.
How would I go about doing this? (As you might tell, I just recently picked up visual studio, and am pretty new to everything)
Thank you.
There are atleast 3 ways to do this:
If you are using SQL Server 2008 or newer this is now built in functionality, see: http://msdn.microsoft.com/en-us/library/bb933994.aspx
If you opt not to use that then the simplest solution is to use database triggers.
If you want to do it in C# code, then you need to read the original values before saving, and save these original values to the history table. For reading original values see: How to get original values of an entity in Entity Framework?
I would go for option 1 if possible.

Current version of data in database has changed since user initiated update process

I have a Master Detail form in my Oracle APEX application. When I am trying to update data in this form, I am getting below error.
Current version of data in database has changed since user initiated
update process. current row version identifier =
"26D0923D8A5144D6F483C2B9815D07D3" application row version identifier
= "1749BCD159359424E1EE00AC1C3E3FCB" (Row 1)
I have cleared browser cache and try to update. But it not worked.
How can I solve this?
I have experienced similar problem where my detail records set has timestamp fields. By default master detail wizard creates the timestamp fields as date picker type fields. If you set the date format on these, it would resolve the issue.
This blog post tries to address this issue on a Tabular Form (I know that's not what the original issue was with, but thought it might be related). It says the same as #sangam does below.
Short version: If you have an updated field that's timestamp datatype, you should set a date/time format.
http://apexbyg.blogspot.com/2015/05/tabular-form-bug.html
My tabular form has a field that's timestamp datatype, but I had already set a date format, so this didn't help me.
Here's another possibility, which I discovered was the case in my application.
That would be if the data the original checksum was calculated on is truly different than the pre-update checksum calculation, due to a design-flaw in your query!
In my application, the source for one of the updateable fields was COALESCE(name_calced, name_preferred). In the source table, the person's name could already be loaded in the record by an external process and we save it to one field - name_calced. But the end-user can enter a preferred name, which we wanted to save to the name_preferred field. We wanted to initially populate the displayed, updateable tabular form field with name_calced, if one existed, or name_preferred if the user had already provided a preferred name. Then they could change that value and save it back to the database.
I finally discovered that the Save action threw the error message if name_calced was non-null, but name_preferred was null. I realized that the initial checksum was calculated based on name_calced, but the pre-update checksum was based on name_preferred, so the application thought someone had changed the value in the background and showed the error message.
What I don't understand is how this problem didn't show up in the past 3 years the application has been running in production!
My solution is to make the field source only on name_preferred, which immediately solved this problem. I also think the back-end process will also get changed to pre-populate that table field from name_calced, so the user always sees the base value, if there is one.
I just had this issue myself. Now, I realize that tabular forms are deprecated at this time, but I have an application that was developed beforehand and still uses them. This issue occurred and I had to get one of our big guns at Oracle to help me out. I do a lot of DB work and a decent amount of Apex development but I'm more of a Java, WebLogic, etc guy, and I really couldn't figure this one out.
In my case, it turned out to be really simple. One of the columns in my tabular form was a hidden field, generated via a sub query. Being hidden, this column is not editable by the user and should not be part of the MRU update. I had the field set to "Hidden Column (saves states)" and setting its type to "Hidden Column" fixed the issue. So, this leads to sub queries being executed in such a way as to change the checksum for the overall query before hitting submit (save), causing the error.
For those who are continuing to troubleshoot this, look at your query for every field that you have specified and note which columns are editable in the tabular form. All other fields should be set in a way that makes them not save state so that they are not part of the update.
I had this error when I had two update processes processing on submit.
My solution was to add a condition to both processing steps. I had forgotten to do this when I made an additional process for Button A, but I never updated Button B to limit it's behaviors.
Navigation:
Processing -> Processes -> [Your Process Name] -> Server-side Condition -> When Button Pressed = [Your button Name]
In my case I had a column from a secondary table that was not set as Query Only and was being updated! The error would occur trying to save a column not in the table being updated. It took me half a day to figure it out (the column names were the same).
Set your Link column hidden to display only in the form.
Set "Send On Page Submit" to 'No' or disable the link column that is your primary key ( Rownum/rowid/id etc).
Hope it will work for you.
I have noticed this error comes when I was working Tabular Form and has disabled one of the form operations i.e. by setting server-side condition to "Never" for add, apply changes (submit) buttons
When I have restored back to its original state, it worked as expected.
In case you have to hide Add/Update button, use some other option.
https://compknowledgebase.blogspot.com/2018/12/oracle-apex-error-current-version-of.html

How to make drop-down menu within Oracle Application Express?

I would really appreciate if anybody could shed some light on this, as search engine results have been singularly unhelpful so far.
I am attempting to build a GUI for an oracle database through Application Express. There tend to be tricks of how to set up drop down menus through the Graphical User Interface of the product that one uses (for instance I would know how to do this in a product like Microsoft Access).
For instance I have this form
The foreign key for Business (FK_BUSINESS_ID) is just an integer - not terribly user friendly! If it could be a drop down list of business names (BUSINESS.NAME), it would be great. Hiding the business primary key (BUSINESS_ID) would make it look nicer, but isn't altogether relevant.
I have found the source controls for the element in question.
What sort of SQL (or even PL/SQL) could be used to both display this data from the other table, and return the selected foreign key selected by the user when the form is sent?
Solution
Open up the item, and change the type to Select List
For List of Values Definition, enter select BUSINESS.NAME, FK_BUSINESS_ID from [TABLE]
Explanation
Select list shows display values to the user and returns the corresponding ID. Your source can remain the same as before.

MS CRM Save + Copy as new (Custom Entity)

I have a custom entity in Microsoft CRM (4.0). The user has to input records however usually they have a batch of 20+ records that are almost the same apart from 2 or 3 fields which need changing. I know I need to write some custom code to enable this functionally. However can anyone recommend any methods to do this.
Ideally there should be a button that will save and create a copy as a new entity.
My Current way of thinking is to pass all the details as part of the URL and use javascript to strip them out on the page load event. Any ideas welcome.
Thanks
Luke
I found the answer here:
http://mscrm4ever.blogspot.com/2008/06/cloning-entity-using-javascript.html
I've used it and it appears to work well.
Since there are numerous fields, but only certain fields values are different, then i am thinking to set the default value to all the fields, so that users just need to alter those values when needed.
In my approach, i will hook a javascript function on load of the form data entry screen and use XmlHttp approach/Ajax approach to hook to the custom web service to pull/retrieve the default values of each fields. Or you can set those values at the javascript function itself, but the drawback of this, it's difficult to customize later. So i will choose the approach to hook to the custom web service and retrieve those value from some application parameter entity.
Your idea of providing a "clone" button is also a great idea, which means that it will duplicate all the attributes of the previous record, into a new record, so that it will save time for data entry person to customize the different value
EDIT
Since you would enter records in batch mode, how about customizing .ASPX screen to enter records. By customizing through .ASPX screen, you can use a tab , so that users can browse through tabs, to customize the value/attribute of each record.
There will be a "save" button as well as "clone" button to clone some common attribute or value.
I would create a custom web service that would accept the entity type and the ID of the record I'm cloning. Your "Save and Clone" button would call the service, and the service would handle the details of retrieving the current record and deciding which fields to set on the new record. The service creates the record, and sends the Guid of the record back to your button, which then opens up the newly created record.
This way, you avoid the messiness of setting/getting values in JavaScript and tying which fields to set/retrieve directly to your OnLoads, as well as avoiding the possibility of query string that's too long.
The service could easily be sufficiently generalized so that all you'd have to do is add your button to any entity, and it would work, assuming you'd set up your service to handle that particular entity.
One possible downside is that since the clone record button would actually create the record, the user would be forced to delete the cloned record if they decided they didn't want to clone the record after all.

Resources