Question: If I have a textbox on an Access form with comments already in the textbox, How can I create a button to insert another comment to append without deleting the current comments? Example: Textbox with first comment. [click button] to add second comment either after the first comment or next line.
[click Button1] with first comment.
me.comment="first comment"
[click button2] that has second comment to append with first comment.
me.comment="with new second comment added without deleting first comment"
to get something like this...
first comment with new second comment added without deleting first comment
What you want to do is called string concatenation, used with a & (or a +) to combine two strings.
You mean that?
Me.comment = "first comment"
Me.comment = Me.comment & " " & "with new second comment added without deleting first comment"
& " " adds a blank between the current and the appended content.
But you could also just use it like this if you add the blank to the string to be added:
Me.comment = Me.comment & " with new second comment added without deleting first comment"
If you want to add a new line between, you can do it like this:
Me.comment = Me.comment & vbNewLine & "with new second comment added without deleting first comment"
Related
I am trying to read from the clipboard and place in an array. I want to validate the first line as the text: "Client Code "
I fill the array with:
tbClipBoardContents.Text = My.Computer.Clipboard.GetText()
For Each strLine As String In tbClipBoardContents.Lines
arrClipBoard.Add(strLine.ToString)
Next
When I give a variable the value of the first array entry it appears correct = "Client Code " in Visual Studio debugging.
Dim test As String = Trim(arrClipBoard(0).ToString)
However when I check using the "IF" statement it tells me it is not correct??
If test = "Client Code " Then
MsgBox("Correct Clipboard Structure")
Else
MsgBox("Not a Valid Clipboard Structure: " & Trim(arrClipBoard(0).ToString)) ' ** Fires this response.
End If
What is doing my head in is that if I copy the value of test from VS debugger and paste it in the if statement it looks like "Client Code " but this time the if statement fires the correct response.
I have tried it by filling the textbox (tbClipBoardContents) using:
tbClipBoardContents.text.split(New [Char]() {CChar(vbCrLf)})
and
tbClipBoardContents.text.split(newvbline)
with the same results.
So does this mean the true value from the clipboard for the line "Client Code " also carries some hidden characters? Any help is appreciated.
Brad
P.S. I have found that if I test the value of Mid(test,1,11) then I will get the desired result, so this is a workaround but would be interested to know what the 12th character is? Perhaps it is the "CChar(vbCrLf)"
As per my observation Trim will have removed the spaces. and you should change the condition to "ClientCode".
The final solution that worked for me was to find the trailing space using Andrew Morton's method above then
arrClipBoard.Add(Trim(Regex.Replace(strLine.ToString, Convert.ToChar(160), "")))
which effectively converted the char(160) to "".
I have a form in Access 2016 with a textbox in which I need to have multiple, semi-colon delimited hyperlinks (which will be dynamically created). What I've decided to do is create a "hyperlink construction string" in VBA, then assign them to the value of the textbox. So, something like:
Me.Field.Value = {link: www.google.com : "Google"} & "; " & {link: www.yahoo.com : "Yahoo"}
...would result in this being in the text box:
Google; Yahoo
My problem is, I can't seem to figure out the syntax to create an individual link in the textbox without making the entire textbox a single hyperlink, which isn't gonna work.
I was working with a few solutions that I've found. I read that this would create the link in the way I need, but it just comes through as literal text with the pound signs:
"Google # www.google.com # Some Argument"
I also tried setting the textbox to rich text, then setting the value to include rich text code for a hyperlink... but that's not working:
"{\field{\*\fldinst HYPERLINK ""http://www.google.com/""}{\fldrslt http://www.google.com}}"
I also thought about designing a Query that will return the hyperlinks. But, I kind of wanted to make it a VBA thing, because I'll have more flexibility in how I create the value. Does anyone have any ideas?
Note: I understand that multiple values should be in a 1:M relational database. They are. But, the requirements of the task are to get all the M values for a 1 entity, then list them out in semi-colon, delimited fashion, which all serve as links to a Details table for the M entity.
Regular textboxes (text only) don't support this.
It is possible with Rich text textboxes. In contrast to the name, they actually use a subset of HTML, not RTF.
With ideas from here I got this working:
Private Sub cmdInsertHyperlinks_Click()
Dim url1 As String, url2 As String
url1 = "D:\tmp\test.jpg"
url2 = "D:\tmp\test space.txt"
Me.rText.Value = "<div>" & _
"file://" & url1 & "" & _
" other text between hyperlinks " & _
"file://" & url2 & "" & _
"</div>"
End Sub
Note: the linked thread says you must URL-encode the links (space to %20 etc), but at least for my simple test, that wasn't necessary.
Note 2: You can't have a different display text and link url, at least I didn't get that to work.
I'm trying to format my listbox so that it looks neat when its in use.
I want to add dollar signs to my numbers, and left align them. Any help would be appreciated. They currently look really sloppy.
Dim salesTotal As Double
customerListBox.Items.Add("Customer: " & " " & "Total Sale: ")
For Each record As DataRow In Me._442_Project_Part_2DataSet.Customers
salesTotal += Double.Parse(CStr(record.Item("YTDSales")))
customerListBox.Items.Add((CStr(record.Item("CustomerName"))) & " " & (CStr(record.Item("YTDSales"))))
customerListBox.Items.Add("------------------------------------------------")
Next
First of all ListBox arn't meant to be easily customizable.
To answer your question I want to add dollar signs to my numbers, and left align them, you need to use String.PadLeft function.
customerListBox.Items.Add((CStr(record.Item("CustomerName"))) & " : $" & (CStr(record.Item("YTDSales"))).PadLeft(8))
Note : I added 8 spaces in this exemple. It might vary depending on the numbers you have. I also added a colon and dollar sign between CustomerName and Sales.
I have a database that I am building where users can add new records at will. The record has a client name which often contains " ' , . special characters. Whenever these appear, the append query bombs out. I know I can filter out these special characters to avoid this, but I don't want to do that if I can help it.
DoCmd.RunSQL ("INSERT INTO tblPlanSpecs ( PlanName ) SELECT '" & (NewPlan) & "'")
I want the user to click the "add new client" button, type in the client and plan names into the text boxes, and then click "add" and this new client/plan name will be added as a new record to the database, and the two text boxes will be populated with the correct client name and plan name. They need to contain the ' " , . etc because that really is the client's name. Is this possible?
Thank you.
You have to use escape characters like the following...
DoCmd.RunSQL "Insert Into tblPlanSpecs (PlanName) Values(" & Chr(34) & Replace([NewPlan], """", """""") & Chr(34) & ");"
Okay, so what i"m doing is creating a word file with my application with my labels and textboxes to create a receipt. In my word file, I am trying to write what is in a first name label beside what is in a last name label.
Here is the code I have, but I just seem to be missing something, because the word file keeps putting a huge gap between the first name and last name. I'm sure it's a very simple fix, but Google doesn't seem to be helping with what I am trying to describe.
printFile.WriteLine("Name: " & vbTab & FirstNameTextBox.Text + LastNameTextBox.Text)
I assume it must be the vbTab keyword.
which is fixed and cannot be changed.
That said you can manage a workaround as follows:
Public Const MyTab = " "
and in your code
printFile.WriteLine("Name: " & MyTab & FirstNameTextBox.Text + LastNameTextBox.Text)