How to format textbox field in Access form to show data the same as in imported file to the table - sql

I have a textbox, which is presenting data from one field in selected recordset. This field contains comments made by user in Excel file, which is later imported to Access table. Each comment is made in separete line and in each it looks ok. Textbox present it as one line, but when I export it to Excel again it looks ok in that new excel.
I have tried changing textbox into rich text format. I have also create other textbox, in which I am able to insert comments and then it looks good.
Textbox source code:
sSql = SELECT LogID, 1Comment, 2Comment, Author
sSql = sSql & " FROM tblGeneralLog"
sSql = sSql & " WHERE LogID= " & Me.ID &
Forms![frmMain_CommentAdd]![txtboxComment2].Value = CurrentDb.OpenRecordset(sSql).Fields(2).Value

Probably, in Excel you don't have a "full new line" (CR + LF). Thus, try:
Forms![frmMain_CommentAdd]![txtboxComment2].Value = Replace(CurrentDb.OpenRecordset(sSql).Fields(2).Value, vbCr, vbCrLf)
or:
Forms![frmMain_CommentAdd]![txtboxComment2].Value = Replace(CurrentDb.OpenRecordset(sSql).Fields(2).Value, vbLf, vbCrLf)

Related

Setting Form Field to autopopulate with previous record entry for text, date, and combo box

I am still very new to most vba coding. I'm trying to do pretty much the exact same thing as with this post:
Microsoft Access Form Setting Default Value to Previous Entry for Both Text Boxes and Drop Down Lists
but nothing from it seems to be working for me. I want to populate each field in the form with the previous record's data via a button Autofill_Click()
Private Sub Autofill_Click()
Me!DateTimeID.DefaultValue = Me![DateTimeID].Value
Me.frmDate.DefaultValue = "#" & Me.frmDate & "#"
Me.Location.DefaultValue = "'" & Me.Location & "'"
End Sub
I'm receiving the error code "type mismatch" for the first line with DateTimeID, as well as an error code "There is an invalid use of the . or ! operator or invalid parentheses." for the second line with frmDate. The third line isn't even throwing an error code, but it isn't populating the desired field (or any field, for that matter) with what I want.
Any help would be much appreciated.
For text:
Me.[DateTimeID].DefaultValue = "'" & Me.[DateTimeID] & "'"
For date/time:
Me.frmDate.DefaultValue = "#" & Me.frmDate & "#"
For number:
Me.Quantity.DefaultValue = Me.Quantity
Code is usually put in control's AfterUpdate event so user doesn't have to do anything other than normal data entry/edit.

Error when passing text values as parameters to Crystal Report Formula field from VB.Net

I am trying to pass some text to a formula field in a Crystal Report.
Formula field name is txtShopName.
shopName is a variable and it has the value of "TORCH-MINIMALL". I use VB.net to view the report and pass the parameter value as follows. However, I get an error when trying to view the report. (Image attached)
What could be the reason?. Is there any specific way which I have to create the formula field in the report?.
Dim crepBill As New repBill
crepBill.SetDatabaseLogon("sa", dbPwd)
crepBill.DataDefinition.FormulaFields.Item("txtShopName").Text = shopName
crepBill.RecordSelectionFormula = "{TB_SALES.bill_no} ='" & "B000002" & "'"
CrystalReportViewer1.ReportSource = crepBill
CrystalReportViewer1.Zoom(100)
CrystalReportViewer1.Refresh()
CrystalReportViewer1.RefreshReport()
Following line sets the formula to TORCH-MINIMALL while it should be "TORCH-MINIMALL"
crepBill.DataDefinition.FormulaFields.Item("txtShopName").Text = shopName
To add the double quotes, change the code as follows:
crepBill.DataDefinition.FormulaFields.Item("txtShopName").Text = """" & shopName & """"
Or you could also use single qoutes, as Crystal Reports support both:
crepBill.DataDefinition.FormulaFields.Item("txtShopName").Text = "'" & shopName & "'"
If showing a text is the only purpose of the formula-field, then one can also use a parameter-field.
The value of a parameter-field can be set as follows:
crepBill.SetParameterValue("nameOfTheParameterField", shopName)

Access 2016 - Multiple text fields - Search as you type not working

I have an Access 2016 Form with 5 text boxes labeled txtprod, txtpri, txtcnt, txtph, txtmfg. I also have a query for my table for the product name, price, count, phone and manufacturer fields.
In my forms 5 text boxes, I would like to be able to auto-search as you type and have my list auto-populate.
I followed these tutorials
https://www.youtube.com/watch?v=SJLQqwMOF08
https://www.youtube.com/watch?v=MwaRFjgwBW8
My form has a form load:
*Private Sub Form_Load()
Dim task As String
task = "SELECT * FROM pricingdata"
Me!details.RowSource = task
End Sub*
And my text box name has this event "on change"
*Private Sub txtprod_Change()
Dim task As String
task = "SELECT * FROM [pricingdata] WHERE ([Product Name] LIKE '" & Me.txtprod.Text & "');"
Me!details.RowSource = task
End Sub*
Search as I type works perfectly fine with just 1 text box. But when I add the following code to my Manufacturer text box event "on change" it doesn't work as intended.
*Private Sub txtmfg_Change()
Dim task As String
task = "SELECT * FROM [pricingdata] WHERE ([Manufacturer] LIKE '" & Me.txtmfg.Text & "');"
Me!details.RowSource = task
End Sub*
Now when I type in my Product name text box, it searched products just fine. When I start typing in my Manufacturers text box, it completely disregards anything I've put into the Product name text box and starts searching as I type only for text in the Manufacturers text box field.
How can I get this setup so all text in all 5 text box fields contribute to the search filter being applied to my list?
Something like this . . .
Private Sub ComboSelect_Change()
' You need to use String delimiters if you want to use a Text Field like:
' Me.Filter "[ATextFieldInRecordSource] = """ & Me.FilterComboBox & """"
' For a Numeric Field, use something like this:
' Me.Filter "[ANumericFieldInRecordSource] = " & Me.FilterComboBox
' Me.FilterOn = True
Me.[Customer_Query subform1].Form.Filter = "[Company_Name] Like '*" &
Replace(Me.ComboSelect.Text, "'", "''") & "*'"
Me.[Customer_Query subform1].Form.FilterOn = True
End Sub
Notice a few things:
The subform is named Customer_Query subform1’
The combobox is named ComboSelect’
Finally, the ‘like clause’ is used in combination with the wildcard character.
Like '*" & Replace(Me.ComboSelect.Text, "'", "''") & "*'"
When you type text into the combobox, the results in the subform are dynamically re-queried.

How can I remove the initial return when the multiple texts are added to the field?

I am asking the user to select a txt file from a specified folder on a server [This is in PowerPoint 2007], but I need to give them the option of selecting more than one, so I have a bit of conditional code to determine this.
One file selected uses this code:
oShape.TextFrame.TextRange.Text = Text
More than one file selected currently uses this:
oShape.TextFrame.TextRange.Text = oShape.TextFrame.TextRange.Text & vbCrLf & vbCrLf & Text
…but this results in an extra return space above it all in the field, which is a bit untidy.
Could anyone advise me on how I can modify this to only get the returns in between the two texts, but not at the beginning?
I am not entirely sure I got the problem, but I believe this will do:
oShape.TextFrame.TextRange.Text = iif(oShape.TextFrame.TextRange.Text <> "", oShape.TextFrame.TextRange.Text & vbCrLf & vbCrLf, "") & Text

AppendText won't append to the next line in a text file / vb

I'm making a program that lets you add student info to an existing CSV text file but whenever I use append text it adds the new info to part of the last line and then a new line.
I want it to do this:
John Doe,29,Male
John Doe,29,Male
It does this instead:
John Doe,29,MaleJo
hn Doe,29,Male
Note: there isn't actually an empty line between each set of info, I just wanted it to be easy to read when I posted it here.
Here is the code for that section:
Dim swVar As IO.StreamWriter = IO.File.AppendText(frmMain.fileName)
swVar.WriteLine(txtName.Text & "," & txtAge.Text & "," & gender)
swVar.Close()
Any help would be appreciated, thanks!
A handy tool in VS2010 (and others) is snippets - right click Insert Snippets... - lots of code patterns for typical tasks. In your case here is a modified snippet:
Sub AddToFile(textToAdd As String, filePath As String)
My.Computer.FileSystem.WriteAllText(filePath, textToAdd, True)
End Sub
You may want to check/add a vbNewLine to the text being added since one is not automatically added as with WriteLine.
Not a direct reply to your stated problem, but an alternate method.
See if something like this works better:
IO.File.AppendText(frmMain.fileName, vbNewLine & txtName.Text & "," & txtAge.Text & "," & gender & vbNewLine)
AppendText will open write and close all in one operation so there's no need for a separate streamwriter. It also doesn't add newlines so those must be added separately
Unless of course you are doing a series of writes to the same file then something like this would probably be more appropriate:
Dim swVar As New IO.StreamWriter(frmMain.fileName, True)
'write your lines here
swVar.WriteLine(txtName.Text & "," & txtAge.Text & "," & gender)
swVar.Close()