Access 2010 - Bound Textbox - Only updating newest record created - ms-access

I am trying to update the textbox for the current request that I have opened. After making changes to the bound textbox (regardless of the record number current being edited) it modifies the tblVendorRequests.VendorDiscussionNotes for the newest request created within the table.
My form is a Single Form
My record source for my form is a table (tblVendorRequests)
My textbox (txtVenConLog) is using tblVendorRequests.VendorDiscussionNotes as its control source
For instance, say I am trying to add notes "Hello World" to request number 242. Request 242's notes remain the same, but the "Hello World is added to the newest record instead (overwriting the existing text that was in the request).
I have done a good amount of searching on the topic, and have not found a satisfactory answer on why this would be.
Any ideas would highly appreciated!

I redesigned my form to split the functions into 2 separate forms and that seems to have resolved the issue. I believe the issue was that when I 'opened' a record, it was not behaving like it would if the record-opening function resulted in calling a form to open with specific criteria.

Related

ms access: 'cannot assign value to this object' message, but assigning value works anyway

I have a strange issue with one of my data entry forms. I have a main form from which I open said data entry form using a button. Once the form is open, I can enter a new record (the DE-form is set to allow additions and data entry is set to YES). The first time AFTER opening the main form, and only the very first time (subsequent tries work as intended), when opening the DE-form from the button and attempting to enter new data into the field "Bezeichnung", I get the following error message:
You can't assign a value to this object.
The weird thing comes now. After clicking OK in the dialogue box, in spite of what the message just indicated, the field contains the character I had just entered and allows me to continue adding data without issue.
After adding the new record and confirming, it shows up on my main form, as well as the related table, as intended. I have tried making a new DE-form from scratch but encountered the same thing. The message only pops up the very first time I attempt to enter new data via the DE-form after opening the main form. Opening the DE-form a second or third time while the main form is still up does not result in the same message. Also, it's the same with any of the fields on the DE-form, not just the first one. After the message pops once, it never shows up again until I close the main form. This is the only DE-form in my project that has this issue, I can#t seem to figure out why. Any help is appreciated.
Database Structure:
Details of my data entry form:
*The DE-form consists of a form with a subform on it (white box in the middle). I have other forms where this is neccesary and in order to keep the design consitent I opted to do the same with this one. Both forms have an invisible textbox bound to stoff_id. The DE-subform has Link Master Field and Link Child Field set to stoff_id
Recordsource DE-form main
SELECT chemikalien_tabelle.stoff_id
FROM chemikalien_tabelle;
Recordsource DE-form sub
SELECT chemikalien_tabelle.stoff_id, chemikalien_tabelle.bezeichnung, chemikalien_tabelle.einsatzgebiet, chemikalien_tabelle.kategorie_id
FROM kategorie_tabelle INNER JOIN chemikalien_tabelle ON kategorie_tabelle.kategorie_id = chemikalien_tabelle.kategorie_id;
I found a solution on another site. Apparently, what is causing the message is an invisible textfield bound to the primary key stoff_id (which is AutoValue) of chemikalien_tabelle on the DE-subform. I usually add the primary key somewhere to my forms since it is likely I will need it. I still don't know why this issue popped up though. The original answer I am refering to did not either Foreign Solution. The post is in German, so check it out at your discretion. Removing the textbox fixes the issue but without it I cannot assign a completely new record. I have a number of other data-entry forms that have the same setup, so I am not sure why this only caused issues in this particular case. Maybe someone else has a an idea?

"Create or update" form behavior when hitting back button

I have the following workflow on a website:
Some user John Doe declares a company through form 1
(fields: name, head office location)
After John Doe submits (HTTP POST) form 1, he is redirected (HTTP 302) to company form 2 with additional legal information about the company.
The problem is, if John Doe hits the back button of his browser during step 2, he will land on the form 1, with data filled by the browser (using values he already submitted — that's what Firefox and major browsers seem to do).
John Doe might then think he can use this form to update some information (e.g. fix a typo in the name of the company) whereas he will actually create a new company doing so, as we don't know on the server side whether he wants to declare a new company or update the one he just created.
Do you know any simple solution to handle that problem ?
Use javascript/jquery script after the page is loaded to empty all the inputs. This will prevent confusion of "updating the company".
jQuery would look something like this:
$('#elementID').val('');
You can also handle the situation by manipulating the browser history
on load of form 2, and pass the CompanyId generated on submit of form 1 using querystring. So that you can actually update the company as the user
Suppose John submits form1.html, a unique CompanyId "1001" is generated and redirected to form2.html. Now on load of form2 you can modify the browser history form1.html?companyid=1001 using
var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 1", "form1.html?companyid=1001");
Now, when the user click back button and submits the form1 again. you can check for companyid in querystring and update the company.
I think it is more user-friendly when user can return back to previous form and update it (instead preventing the described behavior).
I use in most cases similar way to handle described problem:
Let's assume that user is on the page /some-page, that contains "Create new company" button.
When the user opens this page, will be executed special method createOrFindCompanyDraft() on the server-side. This method creates new company "draft" record in DB (only for the current user). For example, draft record has primary key id=473. When you execute this method again it will return the same record with the id=473 (with "draft" status). "Draft" record should't display on any other interfaces.
And "Create new company" has link /company/common/473.
When user go to /company/common/473, you display form 1, that will be filled from "draft" record. At first time user will see empty form.
Technically user will update the existing record, but you can display "Create new company" title on the page.
Then user go to form 2, for example, /company/legal-info/473, you create similar draft record for the this form (similar to step 1).
When user submit the form 2, you will remove "draft" status from the record id=473 (and any related records).
Next time when user open page /some-page, will be created new draft record for the current user.
Browser history will contain:
/some-page
/company/common/473
/company/legal-info/473
/some-page2
I like this approach, because all form only update records. You can go to previous/next form many times (for example "Back"/"Forward" browser buttons). You can close browser, and open not completed forms tomorrow. This way doesn't require any additional manipulation with the browser history.
try this
<form autocomplete="off" ...></form>
And Another
Use temporary tables or session to store the Page 1 form data. If the page 2 form is submitted use the temporary data of page 1 which is stored in database or in session.
Use a Separate key (Hidden field ) in both page 1 and page 2.
Actually I thought of a trick to obtain that "create on first post, update after" behavior (just like the user thinks it should behave).
Let's say the step 1 form is at the URL /create_company/. Then I could have that page generate a random code XXX and redirect to /create_company/?token=XXX. When I create the company I save the information that it was created through page with token XXX (for instance, I save it in user's session as we don't need to keep that information forever) and when the form is submitted, if I know that a company was already generated using this token, I know the user used the same form instance and must have used the back button since the token would be different if he explicitly asked for another company.
What do you think ? (I initially thought there should be a simpler solution, as this seems a little bit over-engineered for such a simple issue)
This is more like a UX question.
I'd think that the solution lies within the information given to the user on that form, to help them understand what they're doing.
Set a title that says 'Create a company', for example, and set your submit button as 'Create Company' will help your user with that. Use a unique id when you create the company object, and pass the id back to the same URL in order to perform an update. You should then update your title and button that tells user that they are updating instead of creating.
In that sense I'd say it's better to use a more generic URL like /company and /company?id=12345.
You could also consider using Restful API protocol to help your server identifies the CRUD operation. http://www.restapitutorial.com/lessons/httpmethods.html
Without the "routing" part of django it is hard to help. I can just answer my experience from the express.js-router functionality:
you can specify a post on /company, which is for new users.
you can specify another route for post on /company/:companyid for a changing form
and as a response from the create-post you can redirect to the different location.

Infopath Linked Fields

Pretty new to Infopath here and I can't seem to google this right so i'm going straight to my last option!
I'm building a form in which a Dropdown list needs to change dependant on the value of another dropdown list
So If X = 1, Then Y = 3 etc.
I'm just not aware of the functionality of Infopath and how I can get something like this working.
Thanks.
What you are looking for can be described at the following post:
Auto-populating an Infopath form after selecting a drop down
Essentially you will be using the rules manager to indicate that when a field equals something it will populate another field with data related to it. Think of it as more complex vlookup. Additionally, the verbage you would want to use to google more on the subject would be along the lines of "infopath auto-populate field based on another fields value".

MS Access 2007 - controlling UI behaviour after attempt to insert duplicate record

Creating a simple UI using MS Access, hoping to do minimal actual coding (actually helping a friend who is not a coder).
Simplified requirement: Single table, primary key is phone number, lots of other non-mandatory fields. Display a form allowing just the phone number to be entered, if a record with that key exists display the full record, if a record with that key does not exist bring up an form allowing the other fields to be entered for this phone number and hence create a new record.
Q1: Any simple way to achieve this kind of function? Example?
We've got some of this going with a standard form, can execute code if insertion fails, but a standard dialogue box is displayed warning about the duplciate key violation.
Q2: How can we trap that attempted insertion, avoid having the dialogue come up?
You will have to get your hands dirty and write some code to get this outcome. A starting point would be something like this presto code. Post back if you get stuck on any of the parts.
If fCheckIfRecordExists(lYourKey)=True then
Docmd.OpenForm “frmEditExistingRecord”
Else
Docmd.OpenForm “frmEnterNewRecord”
End if
Public function fCheckIfRecordExists (lYourKey as Long) as Boolean
‘Code to check if a record exists, simple method is to use dLookup or a count SQL statement with the criteria as the key you are trying to find
End function
EDIT:
First things first make a form with 1 text box called txtPhone_number and a command button called cmdSearch.
Next put this bit of code in the module behind the form
Public Function fDoes_record_exist(strPhone_number As String) As Boolean
If DCount("Phone_number", "tblYour_table", "Phone_number=" & strPhone_number) > 0 Then
fDoes_record_exist = True
Else
fDoes_record_exist = False
End If
End Function
Next you need to put some code behind the click event of the command button. This code can be expanded on to check for a valid phone number later if you want
If fDoes_record_exist(Me.txtPhone_number) = True Then
DoCmd.OpenForm "frmShow_existing_record"
Else
DoCmd.OpenForm "frmEnter_new_record"
End If
That should set you on your way nicely but post back if you run into problems
Here is an overview of the process with Access logic:
You need an unboud control labelled Phone in the form header, where user will be able to enter the phone number to search. You need to use the After_Update event of that control to trigger your search. There will be a second Phone control, bound this time, in the Detail section of the form for effective data entry/update.
Use the Form_Error event to intercept the error message when user tries to save a duplicate key, in order to display a nice message, and eventually Cancel his changes.
The advice from Kevin Ross to use VB Code is clearly one approach, and I think is appropropriate if we anticipate less trivial requirements in future. However I'm in a situation where I'm helping someone with zero coding background and hence if possible I'd prefer to let them use simple Macros rather than full-scale VB.
As it happens the functionality I require can be implemented with just Macros, and it depends on the suggestion from iDevelop.
The outline of the solution I used:
Create an InitialEntry form with no association to any particular table, it has:
a data entry field for the telephone number
a read-only text box where I can display a message
a button labelled Add
a button labelled Show
I write three macros:
A macro AlreadyExists that displays a message saying "We already that one"
A macro NewEntry that opens a data entry form for my table, in Add mode, and which copies the phone number from InitialEntry!TelephoneNumber
A macro TestForExisting this uses a condition
DCount("*","MyTable","[PhoneNumber] = [FormPhoneNumber] " ) > 0
to control whether to execute AlreadyExists, and a similar test to control whether to call NewEntry.
While this is not as efficient as VB, it does seem to be understandable by a non-coder, so at least we can implement our application.

MS Access 2003/2007 - Passing data through a variable on unbound forms vs. a hidden text box

Ok so I hope the title of the question matches what I about to ask, but here is what I am trying to get at:
So I have an access database that uses a number of unbound forms, and the purpose of the forms are to collect data and save to various tables with VBA click events using SQL statements (INSERT or UPDATE based on whether the ID of the record is present on the form in a hidden text box). When entering a new record (via INSERT), I get the row number with
MyRow = db.openrecordset("SELECT ##Identity")(0) 'thanks David
So you maybe getting the picture. If I have another form that relates to the first form in terms of the record, I just open a recordset and pass that value to another hidden text box.
So my question is, is there a better way to do this regarding passing that value (or just using that value) using a variable instead of this awkward method. So I realize a lot of folks are going to go with the obvious answer of, "Why not just make your forms bound instead of all this code"...and I am sure that is a valid answer, however I inherited this database which was already put together like this, and re-structuring it would be a daunting task.
Any and all advice, or learning resources are greatly appreciated, as they always are!
I use unbound controls on forms for all these kinds of values. The current solution of using an unbound form is sounder than using global or form level variables. If I recall the details correctly while debugging code and you hit the stop button you lose all global or form level variables. Or if the user hits an unhandled error.
Have you looked at OpenArgs?
DoCmd.OpenForm "Form1", , , , , , "Hello"