0

I need complete solution to create a template for multiple inputs through textboxes and link those with custom text in the back end. Once all the fields are entered i need the complete message to be displayed and to copy that.

for example Text box 1: Insurance, Text box 2: PHone number and text box 3: Agent name

Output should be

Called "input from textbox 1" with phone number "input from textbox2" and spoke to "input from text box 3"

Need solution if i cannot copy message from msg box option. I am very new to VBA and just saw a simple video to create below solution

Private Sub CommandButton1_Click()
Dim Insurance As String

'get the data from the textbox
 Insurance = TextBox1.Text
 
Dim Phone As String
Phone = TextBox2.Text

Dim agent As String
agent = TextBox3.Text

'create the writeup
'add your code here to manipulate the data

'display the writeup in a message box
MsgBox "Notes: Called" & Insurance, "with phone number" & Phone, "and spoke to" & agent
End Sub

error is received in MSGBOX line.

Mayukh Bhattacharya
  • 12,541
  • 5
  • 21
  • 32

1 Answers1

0

MsgBox expects the complete message text as first parameter. The (optional) second parameter defines what kind of message box you want to display (Icon, Button) and is a numeric value. For details, see the documentation

However, you wrote

MsgBox "Notes: Called" & Insurance, "with phone number" & Phone, "and spoke to" & agent

When you have a closer look to that command, you can see that you are passing 3 strings as parameter, separated by a comma:

"Notes: Called" & Insurance  
"with phone number" & Phone
"and spoke to" & agent

So the second parameter you are passing to MsgBox is a String, while the function expects a number and therefore you get a type mismatch error.

Simply change the command to

MsgBox "Notes: Called " & Insurance & " with phone number " & Phone & " and spoke to " & agent

Now the pieces of the message are all concatenated and result in a single String.

FunThomas
  • 23,043
  • 3
  • 18
  • 34
  • Know that you can "divide" the string in multiple lines using [vbLf, vbCrLf, vbCr](https://stackoverflow.com/questions/27223228/differences-between-vblf-vbcrlf-vbcr-constants). This way the message will looks better. – Evil Blue Monkey Jun 14 '23 at 08:52
  • Sure. You can do a lot. But that was not the question. – FunThomas Jun 14 '23 at 08:59
  • Indeed. I just thought it could have been useful to add an extra tip for Kireeti Srestaluri. Of course it wasn't the point of the question. ;) Should have probably added a reference to him in the previous comment. – Evil Blue Monkey Jun 14 '23 at 09:01
  • Thank you that solution worked. Now I could see the desired result but cannot copy it. Can I get that in a text box rather than a message box where I can copy the final statement – Kireeti Srestaluri Jun 14 '23 at 16:49