Show element only once in report - vba

I am new to access and trying to practice some fundamentals. I am trying to generate a report based on user input from a form.
When the user selects an address a report should be generated with one instance of the address.
As of right now when I create the report on the click from the form.
There are multiple instances been generated of the same address.
The table i am using
AddressLine1
123 Main St.
555 Happy Ln.
456 Main St.
6598 W Street St.
code:
Option Compare Database
Private Sub generateReport_Click()
Dim text As String
text = Me.custAddress
DoCmd.OpenReport "Generation", acViewPreview, "AdressLine1=" & text
End Sub
The outcome is the following...
[![Report outcome][1]][1]
[1]: https://i.stack.imgur.com/wr1Zg.png
I only want it to be printed once.

NVM fixed it by adding a wherecondition
Option Compare Database
Private Sub generateReport_Click()
Dim text As String
text = Me.custAddress
DoCmd.OpenReport "Generation", acViewPreview, text, _
WhereCondition:="AddressLine1 = '" & text & "'"
End Sub

Related

MS Access - Main menu form with 2 text boxes used to open and filter a different form - getting a type mismatch (Run error 13)

I have a main menu where users type in a name of a station (text box) and the name of a cohort (text box) and it would open a new form based on these values. For example, if "New York" was entered for a station and "1b" was entered for cohort, then the form would filter to only show data that have both. However, I am getting a data mismatch error.
The fields text boxed at my main menu are called "detailed_s_station" and "detailed_s_cohort". The names of the respective fields in the form I want to filter these values are called "station" and "cohort".
I can get this to work if there are only one set of criteria (e.g., if I just search for the cohort or just search for the station), however something is going on with my AND here. Any help is appreciated to help me get rid of this data mismatch error.
Private Sub Command41_Click()
Dim stDocName22 As String
Dim stLinkCriteria22 As String
stDocName22 = "frm_scans"
stLinkCriteria22 = "[station] ='" & Me![detailed_s_station] & "'" And "[cohort] ='" & Me![detailed_s_cohort] & "'"
DoCmd.OpenForm stDocName22, , , stLinkCriteria22, acFormEdit, acWindowNormal
End Sub
The problem that you are having is how you are joining the string together. Instead try:
Private Sub Command41_Click()
Dim stDocName22 As String
Dim stLinkCriteria22 As String
stDocName22 = "frm_scans"
stLinkCriteria22 = "[station] ='" & Me![detailed_s_station] & "' And [cohort] ='" & Me![detailed_s_cohort] & "'"
DoCmd.OpenForm stDocName22, , , stLinkCriteria22, acFormEdit, acWindowNormal
End Sub
If you ever have problems like this in future, a quick Debug.Print strLinkCriteria22 would show you the contents of the string that is causing problems.
Regards,

Run-Time error 3075 Access Syntax Error for combobox Search in Access

I am learning about how to create a searchbox with combo box. I was learning with a video in youtube :
Access: How to Create Search Form Using Combo box Part 1
However, when I do my code it doesn't work. :/ I get the Run-Time error 3075 Access Syntax Error.
Private Sub cboVendorSearch_AfterUpdate()
Dim MyVendor As String
MyVendor = "Select * from Vendors where ([vend_name] = " & Me.cboVendorSearch & ")"
Me.Invoices_subform.Form.RecordSource = MyVendor
Me.Invoices_subform.Form.Requery
End Sub
Assuming vend_name is a text field, need apostrophe delimiters.
MyVendor = "SELECT * FROM Vendors WHERE [vend_name] = '" & Me.cboVendorSearch & "';"
Instead of setting RecordSource, an alternative is to set Filter property.
Me.Invoices_subform.Form.Filter = "[vend_name] = '" & Me.cboVendorSearch & "'"
Me.Invoices_subform.Form.FilterOn = True
Would probably be better to use vendor ID for search criteria. Explore multi-column combobox where the ID field is a hidden column but combobox uses the hidden column for its Value yet displays vend_name to user.

Open form to view related records if they exist or open blank form otherwise

Hi I have a form called frmGeneralInformation where the main data is inputted about a book. Then I want a button that opens a form called frmFolio which shows the information about each page in the book. If records about the folios of the book already exist, the existing records should be shown with the option to add more folios. Otherwise a blank frmFolio should be created.
This is my VB code:
Private Sub FolioForm_Click()
Dim Found As Boolean
Found = Not IsNull(DLookup("SurveyID", "tblGenInfo_Folio", "SurveyID = " & .SurveyID))
If Found = True Then
Dim recordID As Integer
recordID = Me.FolioID
DoCmd.OpenForm "frmFolio", , , "FolioID = " & FolioID
Else
DoCmd.OpenForm "frmFolio"
End Sub
But I am getting this error:
Invalid or unqualified error
This is the relationship between the tables:

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.

Line Breaks in MS Access Report

I am using VB.NET and MS ACCESS 2007.
I'm trying to create a header for a receipt.
In my program, I want the user to input the header for the receipt using a richtextbox.
I want to store the user's input to the database and make it a header for the receipt.
Example:
The user's input as shown in the richtextbox is:
Juan Dela Cruz
16
Tokyo, Japan
And when it is stored to the database, it is displayed as:
Juan Dela Cruz [there a symbol in here] 16 [symbol] Tokyo, Japan
The same will also be displayed in the MS Access Report which is what I don't want Access to show me.
I want Access to give me a result the same with the user's input in the richtextbox:
Juan Dela Cruz
16
Tokyo, Japan
How will I be able to do that?
The code executed once the button is clicked:
Try
If receiptEdit = 0 Then
Dim updateHeader = "UPDATE tbl_receiptdetails SET RHeader = '" & boxReceipt.Text & "'"
ExecNonQuery(updateHeader)
MsgBox("Receipt Header Updated")
ElseIf receiptEdit = 1 Then
Dim updateFooter = "UPDATE tbl_receiptdetails SET RFooter = '" & boxReceipt.Text & "'"
ExecNonQuery(updateFooter)
MsgBox("Receipt Footer Updated")
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
#GM-XileGM-Xile:
The Solution from my comment, as answer:
replace
boxReceipt.Text
with
boxReceipt.Text.Replace(vbCr, vbNewLine).Replace(vbLf, vbNewLine)