Copy and paste multiple values in form (1 Viewer)

jaryszek

Registered User.
Local time
Today, 03:54
Joined
Aug 25, 2016
Messages
756
Hi Froth.

I only can say : your database is awesome !!! And you are awesome !
There is so many things which i can use in my model - I am excited!

Could we please explain your sample model step by step in details (questions below)?
I understand a lot but not all unfortunately.

Code to search within Client Form:

Private Sub cboFinder_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ClientID] = " & Str(Nz(Me![cboFinder], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

I love it! This is very quickly method. I have learned a little bit about this and it is the most efficient way to lookup within table.

This query is master level:

INSERT INTO tblClientDocuments ( ClientID, DocumentID, ReceiptDate )
SELECT [Forms]![frmClients]![txtClientID] AS ClientID, tblDocuments.DocumentID, Date() AS ReceiptDate
FROM tblDocumentStaging INNER JOIN tblDocuments ON tblDocumentStaging.DocumentID = tblDocuments.DocumentID
WHERE (((tblDocumentStaging.Assign)=True));

This append query thanks to inner join is inserting all choosen documents.
I do not know exactly how it is working.
I understand inner join from QlikView:

https://community.qlik.com/thread/39177

So here inner join is cloning all Clients ID for each document.
So if you have client ID 1, and 3 documents for it, this query will add 3 rows:
ClientID, DocumentsID, RecipeDate
1 3 Now()
1 1 Now()
1 10 Now()

What is causing that ClientID and RecipeDate is cloned here? How this is working? Sorry for noob question - i have to understand it fully.

Second Question:

I would like to add into tblCLientDocuments possibility to see also document name.
How it is the best way to do it?
Add to tblCLientDocuments DocumentName and Document ID and show only DocumentName ? Add it also in qryAssignDocuments?

Please help,
I am thank you once again !

Jacek
 

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 06:54
Joined
Oct 17, 2012
Messages
3,276
Hi Froth.

I only can say : your database is awesome !!! And you are awesome !
There is so many things which i can use in my model - I am excited!

Could we please explain your sample model step by step in details (questions below)?
I understand a lot but not all unfortunately.

Code to search within Client Form:

Private Sub cboFinder_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ClientID] = " & Str(Nz(Me![cboFinder], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
I love it! This is very quickly method. I have learned a little bit about this and it is the most efficient way to lookup within table.

While I do often set things like that up manually, that particular trick was done by the combo box wizard. One of the options you're given when you place a combo box in a header or footer is to have the combo box navigate the form to a selected record. If you choose that option, the wizard writes the code you quoted.

This query is master level:

INSERT INTO tblClientDocuments ( ClientID, DocumentID, ReceiptDate )
SELECT [Forms]![frmClients]![txtClientID] AS ClientID, tblDocuments.DocumentID, Date() AS ReceiptDate
FROM tblDocumentStaging INNER JOIN tblDocuments ON tblDocumentStaging.DocumentID = tblDocuments.DocumentID
WHERE (((tblDocumentStaging.Assign)=True));
While I thank you for the compliment, it really isn't warranted. That query is just a basic one thrown together in the query editor. That thing is an amazing tool for both newer developers and just throwing together straightforward but long queries. I tend to use it all the time, just because it's usually faster than manually typing out the query.

This append query thanks to inner join is inserting all choosen documents.
I do not know exactly how it is working.
I understand inner join from QlikView:

https://community.qlik.com/thread/39177
INNER JOIN simply means that, in order for a record to be shown, both
fields must contain matching data. That is, for example, how you show both an invoice and the line items ON the invoice. In your case, it allows you to show Clients and assigned documents in the junction table.

So here inner join is cloning all Clients ID for each document.
So if you have client ID 1, and 3 documents for it, this query will add 3 rows:
ClientID, DocumentsID, RecipeDate
1 3 Now()
1 1 Now()
1 10 Now()

What is causing that ClientID and RecipeDate is cloned here? How this is working? Sorry for noob question - i have to understand it fully.
Basically, the query takes all the document IDs from the staging table where Assign was set to TRUE, then adds an entry to the junction table (tblClientDocuments) for each of those document IDs, along with the date they were added. The rest of the fields in the junction table are left blank for future editing.

Edit: The ClientID is cloned because it is on the 'ONE' side of a 'One-to-Many' relationship. For each ClientID, there can be multiple instances of DocumentID. As to the date, note that in the query, instead of referring to a saved value, I'm setting a specific value via the Date() function. Whenever you do something like that, the indicated value is set in all affected records.

Second Question:

I would like to add into tblCLientDocuments possibility to see also document name.
How it is the best way to do it?
Add to tblCLientDocuments DocumentName and Document ID and show only DocumentName ? Add it also in qryAssignDocuments?
You don't - doing so is a violation of normalization as well as a waste of space and energy. Any time you need to display the document name, you can use the relationships between the tables (GO CHECK OUT THE RELATIONSHIP BUTTON ON THE DATABASE TOOLS TAB OR TOOLBAR MENU!!!) to display the document name.

In fact, drop everything else right now and go read up on database normalization. Some options might be THIS or THIS. Uncle Gizmo might have a tutorial on it over on YouTube, too. And you can always ask questions here, but in a nutshell, it means that each table should be about one thing and only one thing, and data shouldn't be saved in multiple locations.

For example, in my setup, if you decide to change the stored name of a given form, you only need to update it in the documents table. If you put the name in the junction table as well, then you'd need to change it in every single record that contains it. At work, I deal with tables with tens of millions of records accessed by hundreds of users at the same time; imagine the impact if I had to constantly update millions of records dozens of times a day.

Anyway, the database I uploaded wasn't finished. The next step would have been to add code to the 'Assign Documents' button on the documents form that runs the append query you looked at, then closes the form and requeries the documents subform on the Client screen. Once the documents have been added to tblClientDocuments, the subform will display the new documents.

In fact, I'm attaching a completed, working copy to this post. Make sure to check out the Relationships tab - that helps you keep your data clean. Also, note the hoops I had to jump through to make VBA run the append query - unfortunately, when you're directly referencing a form in a saved query being run by VBA, you have to do what I did. (The other option is to create the query in VBA and parse in the values at runtime. I tend to avoid it due to database bloat, but it's a very minor amount of bloating and is really just personal preference.)
 

Attachments

  • Sample_multipledocuments.mdb
    728 KB · Views: 104
Last edited:

jaryszek

Registered User.
Local time
Today, 03:54
Joined
Aug 25, 2016
Messages
756
Thank you Frothingslosh very much !

Now I finally understood how to use data normalization!
If you want to add something you simple creating query, you dont have to add filed to the table when your database is normalized, wow it is simple ! Now i am seeing purpose within normalization...:)

So query it can be a final report which i can show to managers via Excel report :) (the dont have even access runtime).
This is very very useful what you have wrote here, thank you for that.

Eval function and referencing to form field also is important here. (this function is something like Evaluate in Excel VBA - i know it).

Thank you once again,
I am closing the topic and marking it as solved.

Best wishes and have a nice day!
Jacek
 

jaryszek

Registered User.
Local time
Today, 03:54
Joined
Aug 25, 2016
Messages
756
One more question Froth:

Why are you creating Close and exit button if user can also simply push The "X" button in order to exit?

Is the method to avoid this in the future?

Jacek
 

Attachments

  • Form.jpg
    Form.jpg
    93 KB · Views: 103

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 06:54
Joined
Oct 17, 2012
Messages
3,276
Habit, mostly. A number of my apps have things that need to be done or checked or verified before a form closes, and sometimes I need the ability to cancel a Close if something is wrong, and you can't do that once the Close event has triggered.

Because of that, I'm just in the habit of removing the X button from forms altogether, as well as disabling the application's 'X' button and intercepting Ctrl-F4 and Alt-F4. Better that than risk someone's hospital claim getting messed up because someone closed out of a half-changed record.

Plus, from a UI standpoint, having database navigation buttons is just more professional.

To be honest, in the case of the demo, it was pure habit. The button only took a few seconds to create, after all.
 

jaryszek

Registered User.
Local time
Today, 03:54
Joined
Aug 25, 2016
Messages
756
Thank you Froth,

This is worth to remember.

Jacek
 

jaryszek

Registered User.
Local time
Today, 03:54
Joined
Aug 25, 2016
Messages
756
I have one more question - I was thinking about yestarday during night (could not sleep).

We have table tbl_clients with Autonumber ID field and ClientTypeID as number.

ClientTypeID is an foreign key for field ClientTypeID (primary key) in tbl_ClientTypes.

So user when will be inputing new clients into tbl_clients should know ClientTypeID?
So user has to know that client Frothingslosh is Commercial and has to know that commercial type has ID = 2 .

In my company there can be a problem for that - people will be protesting - they want to have only text to write...

How do you Guys solving problems like this? Simply inform your users abot dictionary for sepcific fields?

Best Wishes
Jacek
 

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 06:54
Joined
Oct 17, 2012
Messages
3,276
Honestly, you'd be better off asking new questions in new threads. People generally assume that threads marked solved are, well, solved.

That said, GO READ ABOUT DATABASE NORMALIZATION. Had you done that, you'd know the answer to your questions.

Note in the demo I posted here that there are primary and foreign keys, and at no point does the user ever touch either one.

Please that in that main form, Client Type was a combo-box, so that the user was to select one of the presented options and at no time ever saw the foreign key itself.

Also, go look up forms vs subforms and how they relate to relationships and basic data integrity - they are the best way to access data from related tables at the same time in one form. That's what I did in that main form with it displaying the selected client and the bottom half showing all documents assigned TO that client.
 
Last edited:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 11:54
Joined
Jul 9, 2003
Messages
16,304
Use a combobox...

Sent from my SM-G925F using Tapatalk
 

Users who are viewing this thread

Top Bottom