473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to: Combobox text inserted as part of a texbox standard message.

I have a textbox on a form with a standard message that has a few blanks in it. I want to be able to fill in the blanks based on text from combobox selections.

ComboboxItem select options are: TrainingBook 1, TrainingBook 2, TrainingBook 3.

ComboboxLocations select options are: Northern Region, Southern Region, Eastern Region, Western Region.

The standard text looks like: Thank you for ordering _________ for the ________ of operations. Your order was received on_______ and should be shipped no later than ________. Thank you once again for your order!

I’ve started sort of like this --

Textbox source =“Thank you for ordering” & [comboboxItem] & “for the” & [ComboboxLocations] & “of operations. Your order was received on” & [datebox] & “and should ship by”, =adddate([datebox]+2), & “Thank you once again for your order!”

Thank you for your help!
Mar 7 '16 #1

✓ answered by jforbes

  • Open your Form in Run Mode.
  • Open the VBA Editor code by hitting the Alt+F11 keys.
  • In the Editor's upper left shoudl be a list of your Forms, double-click on the Form you are working on to open the Form's Code.
  • Go to the bottom of the code and Paste in the Code from Post #2
  • You may have to tweak the code a little bit to get it to work. First thing to do is to click Debug|Compile to see what errors Access can find with the Code. It most likely will find errors with the names of your TextBoxes and ComboBoxes as I only can guess what their names are.
  • Second, once it compiles, you'll want to test the function. The easiest way I know how to do this is by using the Immediate Window. To open it, if it isn't open already, hit Ctrl+G on the keyboard.
  • In the Immediate Window, type the following and hit enter: ?Form_[yourFormName].generateConfirmation() (You'll need to type in your actual Form Name for [yourFormName])
  • Your code should execute and if there are errors, the debugger will highlight them. The Question mark is shorthand for Debug.Print, so a question mark followed by a function, will run the function and print the results to the Immediate Window.
  • This is some good documentation on how to Debug in VBA and if you don't feel confident with debugging VBA, reading this should actually be your first step before anything else.
  • Once the code is working, put the following into the ControlSource of your TextBox: =generateConfirmation()
  • Enjoy your new TextBox

3 989
jforbes
1,107 Expert 1GB
What you are attempting to do should work, but typing all that into the ControlSource is not the easiest thing to troubleshoot. I would recommend creating a function in your form to knit a text string together and return it, then you can use this function as the ControlSource and then you can debug what is going on.

For example, you could create a function like the following and set the ControlSource to =generateConfirmation():
Expand|Select|Wrap|Line Numbers
  1. Public Function generateConfirmation() As String
  2.  
  3.     Dim sComboboxItem As String
  4.     Dim sComboboxLocations As String
  5.     Dim ddatebox As Date
  6.     Dim dShip As Date
  7.     Dim sReturn As String
  8.  
  9.  
  10.     sComboboxItem = Nz(Me.ComboboxItem.Value, "")
  11.     sComboboxLocations = Nz(Me.ComboboxLocations .Value, "")
  12.     ddatebox = Nz(Me.datebox .Value, ddatebox )
  13.     dShip = dateadd("d", 2, ddatebox)
  14.  
  15.     sReturn = sReturn & "Thank you for ordering "
  16.     sReturn = sReturn & sComboboxItem  & " for the "
  17.     sReturn = sReturn & sComboboxLocations & " of Operations.  "
  18.     sReturn = sReturn & "Your order was received on "
  19.     sReturn = sReturn & ddatebox & " and should ship by "
  20.     sReturn = sReturn & dShip & ".  Thank you once again for your order!"
  21.  
  22.     generateConfirmation = sReturn 
  23. End Function
Mar 7 '16 #2
jforbes,

Thank you for the answer and I've looked into implementing your instructions; however, I am not at a level to full comprehend how to do this. Would you mind, if you have the time, pointing me in the right direction or walking me through how to create this function.

Than you in advance!
Mar 9 '16 #3
jforbes
1,107 Expert 1GB
  • Open your Form in Run Mode.
  • Open the VBA Editor code by hitting the Alt+F11 keys.
  • In the Editor's upper left shoudl be a list of your Forms, double-click on the Form you are working on to open the Form's Code.
  • Go to the bottom of the code and Paste in the Code from Post #2
  • You may have to tweak the code a little bit to get it to work. First thing to do is to click Debug|Compile to see what errors Access can find with the Code. It most likely will find errors with the names of your TextBoxes and ComboBoxes as I only can guess what their names are.
  • Second, once it compiles, you'll want to test the function. The easiest way I know how to do this is by using the Immediate Window. To open it, if it isn't open already, hit Ctrl+G on the keyboard.
  • In the Immediate Window, type the following and hit enter: ?Form_[yourFormName].generateConfirmation() (You'll need to type in your actual Form Name for [yourFormName])
  • Your code should execute and if there are errors, the debugger will highlight them. The Question mark is shorthand for Debug.Print, so a question mark followed by a function, will run the function and print the results to the Immediate Window.
  • This is some good documentation on how to Debug in VBA and if you don't feel confident with debugging VBA, reading this should actually be your first step before anything else.
  • Once the code is working, put the following into the ControlSource of your TextBox: =generateConfirmation()
  • Enjoy your new TextBox
Mar 9 '16 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Thelma Lubkin | last post by:
I am trying to limit the user's options to the choices offered by the combobox text, but I don't want this to extend to how he spaces out the text, e.g. 'abcdefg' and 'ab cd efg' should be...
1
by: thomaz | last post by:
When i make an update in my database, the modifications are showing in all TEXTBOX but i can´t see the new values in a combobox text. If i close the form and open it again the new values will...
0
by: thomaz | last post by:
I use the DataSource like below to fill a Combobox: comboBox1.DataSource = dataSet1.Tables; comboBox1.DisplayMember = "ProductName"; When the user types any keyboard key i use the DROPDOWN...
7
by: tshad | last post by:
I have been sending messages to myself from work that worked before and now all of my message only seem to be sending part of my messages. I get the first part of the message and then get...
1
by: Richard Bond | last post by:
Hi, I have a combobox that is bound to a list of text and values in a dataset. It is in Dropdown mode - which enables the user to type in their own text if they so wish. when I process the form,...
5
by: Agnes | last post by:
I got two comboBox A & B, If use choose B, the text in combobox should be blank.\ I try combobox.Text, selecteditem,displaymember = "" But It seems useless. Please help Thanks
3
by: JD Williams | last post by:
Greetings, I have a combobox that I have data added to when I defined it. Like so: 'cbDCs ' Me.cbDCs.Items.AddRange(New Object() {"ADC1", "ADC2", "ADC3"}) Me.cbDCs.Location = New...
0
by: ohpato | last post by:
Hello, I want to encrypt a part of SOAP message using Java. I found an WSS4J example, but it only explained an encryption of SOAP envelope. I hope to know how I can encrypt a part of SOAP...
10
by: news.microsoft.com | last post by:
I am new to this so bear with me. I have a set of combo boxes. Lets call them ComboBox1 and ComboBox2. ComboBox1 items are pulled from a table. When a user selects a certain item I want to...
5
by: itsolution | last post by:
Following is a snippet of FreeBSD man page. It seems to indicate search.h is a part of Standard C library. True? What's the exact list of Standard C library headers? Looks like most modent OS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.