Access Form switches unintentionally between Datasets - vba

I am rather new to coding an Access Application and I have a rather strange error I do not seem to be able to resolve.
I have multiple Forms which are used to write data to some tables. Basically one Form per table.
Mostly the forms are just used to show a selection of the data in the tables. To make sure that noone accidentally alters some data you have to press the button "alter" first, which unlocks the fields to alter the dataset. In one form, however, when you ppress the alter button it switches the dataset. I have one column which is an automated ID which serves as a primary key to distinguish the data from one another.
So when I am debugging the issue and print this ID (Debug.Print Forms(formName).Controls("ID")) it returns the ID of the data that I want to alter, but as soon as I access the data and change one field (Forms(formName).Controls("Column1") = "foo") and print the ID again the ID switched to a completely different dataset.
I have absolutely no clue how that could happen. There is no other code being processed in between. I have googled for multiple hours but have not found anything in this regard yet. Maybe I am just using not the right keywords.
Any help is highly appreciated.
Thanks in advance :)

Related

How to make records read-only once entered in query?

I have a form that a user will input data into, which will then send the added record to the backend of the database (I split the database so that the frontend is accessible to users while the backend is hidden). The frontend also includes a query with no filters, so that it will full portray the backend. This way, users can either input data via the form one record at a time, or add multiple records to the query (and therefore the backend) by copy/pasting from an excel sheet with a specified format (so that the data will be pasted in the same order as the fields of the query).
I want the user to not be able to edit the data/record once it is submitted, but I still want them to be able to view it in the query and/or paste multiple records in the "(New)" record row. Is there a way to make all entered records "read only" per se, but still have the ability to enter new data (i.e. make user unable to edit previous records, but be able to add new records)?
I used this forum as a reference, but the only solution I've come up with was to make the Recordset Type "Snapshot", which does all that I want, except it disables the ability to add a new record.
https://answers.microsoft.com/en-us/msoffice/forum/all/lock-the-entire-record-once-certain-textboxes-have/24f53c0a-2435-48b2-bf91-6713ff8b60ee
I've searched far and wide, but unfortunately haven't come up with anything. Any help would be greatly appreciated. Thank you!

Any ALV-specifics with itab created by RTTS?

I create internal table by two steps, both refer to the RTTS-techniques.
The first step loads and parses a tab-delimited file into a table.
The second step reads this table by RTTI, then, hardcoded, adds some other columns in front of the old columns from the file and, finally adds the old fields back again, the table now has about 12 new hardcoded columns, in front of those from the file. The RTTS helps to create the final table, which then is passed as the data source to the ALV grid.
My former requirement did not take into account that the ALV-grid-toolbar-functions will ever be needed by the end-user, however, as always, this has changed. I enabled the toolbar functions, the default ones, without any custom button.
So, now the user can remove some columns from the display or add them back again, she/he can also change their order. Everything is fine but I never encountered this situation with a table, which is created during runtime.
Are there special culprits I need to be aware of ?
<ITAB> created using RTTS functionality is fully supported either by the REUSE_ALV_LIST_DISPLAY or one of ALV OOPS technologies. All the layouts should work fine. In fact I think in the cl_salv_table=>factory RTTS is responsible for automatic creation of the field catalog of the ITAB since it do not need field catalog passed by the parameter. The only thing that I heard is lost pointers of the <ITAB> ant this leads to refresh problems and so on but this is different story.
From my experience, ALV column maximum size is 120 characters. So if your file could have more than that, you could have a problem. Otherwise, do not expect any major thing.

Printing Form (on current record)

I have a form that computes a very extensive calculation based on inputs which are all saved in a table (declared by Control Source) by a unique identifier.
I export this data into Excel and reformat with a macro. I lose the formatting of the form.
I found that with the form active, I can print this form. The print includes multiple form copies for each record in the table and I do not see this being very user friendly.
I investigated online and see the typical workaround would be to print the unique record based on a report, though I would again lose the layout of the form.
My question would be, if I create a copy of the table I am storing my data in (as to capture all columns I am currently using on the original table) and maybe even the form I desire to print, could I have an on-click procedure that would save only the current record and all its inputs to the "PrintTable", and be able to print only the current record, then after it prints clear the table of any records?
Providing answer as unable to comment.
Can you not recreate the form as a report? Forms are not designed to be printed, however Reports are specifically designed for this purpose. And you can pass through criteria onto a report. And have virtually the same sort of design as you can put on a form.
Creating a duplicate table just to overcome the issue you are facing flies in the face of normalisation techniques, and should absolutely be avoided at all costs.

Access: Update and Append in same form

I am new to using the front end tools/VBA in access, but I am an advanced programmer.
I have a situation where I need to record the date, and method of commute, for a particular individual on a monthly basis. What I have done so far is programatically create a form that lists every day of the month and has a blank space next to it for the user to enter in how he commuted. User only has to fill in if he/she clean commuted. The question is, how do I:
1. Select Records that have already been entered for a month and populate them to a line on my form.
2. Show a blank space for a user to enter info on any date that is not associated with a record.
3. Update any records they changed.
4. Append any new records they enter in the blanks.
I need to do this all on one form so it is easy. I cannot ask the users to navigate.
I appreciate any suggestion that might lead me to a solution. Many thanks.
A standard bound form will do that.
Use the wizard to get started and specify your table as the source.
After much testing and working (strange not find examples of this), I have determined the way to do this.
Do not programmatically create the form.
a. Forms in Access are tied so closely to accesses "form binding" functionality that there are to many limitations trying to work with a programmatically created form. It's very difficult to do.
A better solution is to programmatically create a temporary table that has the correct data structure and bind the form to that temp table.
a. thus the only programmatic part of your form is setting the bindings. Once that is done, you can rely on the form binding in Access to work easily with your Select, Update, and Append functions.

Display multiple query results in a list box?

My Access form has a list box that displays files the user has selected from an OpenFile dialog box. What I do is copy these list box files into a seperate folder on the network and I save this network path in a tblAttachments table. This table has a one-to-many relationship with my main table - tblIdeaDetails.
I created a query that selects records from the tblAttachments table:
SELECT tblAttachments.attachmentPath, tblAttachments.attachmentIdeaID
FROM tblAttachments
WHERE (((tblAttachments.attachmentIdeaID)=[Forms]![frmIdeaSubmission]![ideaID]));
My question is, how can I display the results of this query in that same list box when the user is navigating through the records (frmIdeaSubmission in this case, which is bound to the tblIdeaDetails table)? I've tried doing a requery, but I kept getting an "Out of stack" error.
There isn't a lot of information to go on with your question but let me see if I can help anyhow.
My suggestion is to isolate your problem and work it out before incorporating it into your project. Create a new access database and make a 'demo' of what you are trying to accomplish.
The reason I'm suggesting this is because an 'Out of Stack' error is memory related - could be related to database corruption - a whole myriad of reasons.
Microsoft Support lists a few reasons:
http://msdn.microsoft.com/en-us/library/aa264523(v=vs.60).aspx
As identified by the support page, it can be dependent upon a number of factors that are going to be present throughout the database.
All things being equal, if you have your listbox recordsource bound to the query you indicated - calling the requery method on the listbox object should do the trick. Changing the record should also force a requery if its bound to a data source.