Concatenating fields

loki

Registered User.
Local time
Today, 07:59
Joined
May 4, 2001
Messages
58
I have a main form with a Revision History field. I created a button on the main form that when pressed opens a Revision Hisory Adding form for adding new details. There is three fields on my Revision History Adding form, name (which gets it's value from the main form), date (which defaults to today's date) and comment. When a user enters a comment in the Revision History Adding form and hits save, I want the three field values to concatenate and then that concatenated value to be brought back to the main form and concatenated with whatever value is in the Revision History field on the main form. Can anyone help me with the code for accomplishing this.
 
There are a couple of possibilities. Idea 1:

Don't do the work in the main form, do it in the Revision History Adding form. When the "OK" button is pressed, and before you close that form, do something like:

Forms!frmMain!txtRevHist = Forms!frmMain!txtRevHist & Me!txtName & Me!txtDate & Me!txtComment

To make it readable you'll perhaps want to add carriage returns into the concatenation (using the constant vbCrLF) but the principle should work.

Idea 2: In the main form, in the click event for the button that opens the RevHistAdd form:

DoCmd.OpenForm "frmRevHistAdd",,,,,acDialog
Me!txtRevHist = Me!txtRevHist & Forms!frmRevHistAdd!txtName & Forms!frmRevHistAdd!txtDate & Forms!frmRevHistAdd!txtComment
Docmd.Close acForm, "frmRevHistAdd"

Because the main form opens frmRevHistAdd modally as a dialog form, its execution stops until that form is closed or hidden.

What you do in frmRevHistAdd is make the "OK" button hide the form itself (Me.Visible = False) rather than close the form. Its values are then available to the main form which can close the RevHistAdd form when it's finished with it. Of course, you'll want to make the code a bit more sophisticated than in the example, to cater for eventualities like a "Cancel" button being pressed on the RevHistAdd form but again the principle should work.

Hope this helps,

Simon.
 
Thanks it worked! I used idea #1 and it worked great.
 

Users who are viewing this thread

Back
Top Bottom