Passing pre-defined text from Form to Form

leighj

Registered User.
Local time
Today, 17:53
Joined
Apr 5, 2017
Messages
10
Hi All...

I'd really appreciate some help. I'm fairly new to Access and VBA... and I'm working on a project for an issue logging system.

Here's what I'm trying to achieve. I've got my "New Issue" form (FORM 1)(frmNewIssue) and on that contains an 'Template' button (btnTemplate) and lots of other fields - such as summary, details etc.

What I want to happen is that when someone clicks the template button, this loads a new form (FORM 2) - which has a list box or similar, where the user can select different 'repeat' issue types.

If they select one of the templates on the list box and click an 'OK' button - I want FORM 2 to populate my Summary and Details field on FORM 1 with pre-defined text.

I've seen this happen in lots of different databases - but I've been googing and searching to try and find a way to do this, and I'm struggling.

Really appreciate any help.

Cheers,

Leigh
 
Why the need for a new Form2 ? Why not have the combo box on your initial form.
 
Why use a separate Form with the Listbox? Why not simply hide the Listbox until needed, pop it up using the template button, use its AfterUpdate event to populate the target field?

Linq ;0)>
 
Thanks for your replies.

I guess I just thought it would be better, layout wise, if it was sat on another form... as the templates wouldn't be used on every data entry.

But just going with what you have suggested...

I've inserted a new table (tblTemplates) with three fields, ID, Title, Template.

I've put in my Combo Box, and made it non visible. Set the template button to make it visible.

How would I now go about getting the data stored in the 'Template' field placed into the "txtDetails" field - related to that template?

For example.. if a user selects "First Aid" from the cbo, the data in "Template" in the tblTemplate loads in?

Sorry I'm new to this. Really appreciate help.

Cheers,

Leigh
 
Set your combo so it has 2 columns, the row source based on tblTemplates, the first column being Template, the second being Title. Make the column width of the first column 0 so it is not displayed in the combo.

In the afterUpdate event of the combo, add the line
me.txtTemplate = me.cboTemplate
 
Set your combo so it has 2 columns, the row source based on tblTemplates, the first column being Template, the second being Title. Make the column width of the first column 0 so it is not displayed in the combo.

In the afterUpdate event of the combo, add the line
me.txtTemplate = me.cboTemplate


That works great! Thank you!
The only other thing that I would like it to do (not sure if it's possible) is if a template is selected, it does not overwrite all of the txtTemplate field - but instead adds the template to the end.

So if I load the form, and type in some immediate notes into the txtTemplate field - I may then want to add a template to the end of the details.

Is there a way I can achieve this?

Many thanks in advance... you guys are great!
 
Replacing YourComboBox with the name of your Combobox and TargetTextBox with the name of the Textbox to hold the data:

To add your selected data on a new line:

Code:
Private Sub YourComboBox_AfterUpdate()
 If IsNull(Me.TargetTextBox) Then
   Me.TargetTextBox = Me.YourComboBox
 Else
   Me.TargetTextBox = Me.TargetTextBox & vbNewLine & Me.YourComboBox
 End If
End Sub
To add your selected data to the current line, separated by a Comma:

Code:
Private Sub YourComboBox_AfterUpdate()
 If Nz(Me.TargetTextBox, "") = "" Then
   Me.TargetTextBox = Me.YourComboBox
 Else
   Me.TargetTextBox = Me.TargetTextBox & ", " & Me.YourComboBox
 End If
End Sub

Linq ;0)>
 
That's perfect, thanks so much for your help :)
 
Glad we could help!

Good luck with your project!

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom