MS Access: Concatenate two fields into existing field - sql

I have a form with 5 combo boxes. As an example (maybe a poor one):
CBO1 is username (in table), CBO2 is Lastname (value list).
I would like to concatenate CBO1 and CBO2, and save as CBO1 to my table. Is this possible? Thank you.

For the form field CBO2 add an event procedure "after Update".
Private Sub CBO2_AfterUpdate()
Me.CBO1 = Me.CBO1 & " " & Me.CBO2
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,

update table through form

This is the next attempt I am making at solving this problem. In my timeline is the prior attempt.
I have three tables BOAT, BERTHAGE, LOCATION. These tables are joined in the following way in a query called Boat_Move
BOAT(boat_ID) joins to BERTHAGE(boat)
LOCATION(Loc_ID) joins to BERTHAGE(location)
This query is viewed on the form as a subform.
When the form opens up I will highlight the vessel which needs to have its location moved/updated
Once highlighted in the subform I click the edit button
Private Sub cmd_Edit_Click()
If Not (Me.Current_Week_Boat_Move.Form.Recordset.EOF And Me.Current_Week_Boat_Move.Form.Recordset.BOF) Then
With Me.Current_Week_Boat_Move.Form.Recordset
Me.txt_Boat = .Fields("BOAT_NAME")
Me.txt_Cur_Loc = .Fields("LOCATION")
Me.txt_Cur_Flo = .Fields("FLOAT")
Me.txt_Cur_Doc = .Fields("DOCK")
Me.txt_Cur_Ori = .Fields("ORIENTATION")
Me.cmd_Add.Caption = "Update"
Me.cmd_Edit.Enabled = False
End With
End If
End Sub
This puts the appropriate information into the text boxes.
I've also did up the following with the idea that this would update the location(field) in the BERTHAGE(table)
Private Sub cmd_Add_Click()
Dim strSQL As String
strSQL = "INSERT INTO BERTHAGE(BOAT, LOCATION)" & _
" VALUES(" & Me.txt_Boat & ",'" & Me.txt_Cur_Loc & "');"
CurrentDb.Execute "UPDATE BERTHAGE " & " SET LOCATION=" & Me.txt_Cur_Loc & _
" WHERE LOCATION=" & Me.txt_Cur_Loc
Current_Week_Boat_Move.Form.Requery
cmd_Clear_Click
End Sub
I'm not sure if in this instance I should be creating a new table to make the update and then overwriting the older table. The issue I see here is the older table is at around 24k records so that doesn't seem like the best way forward.
So at this point I'm facing two problems, and I am unsure if solving either one will solve the actual problem of updating the BERTHAGE(location) field.
View of the from
Any help is appreciated.

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

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)

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.

Vb.Net Combobox DisplayMember

I got a combobox ("cmb") with a dataset (Surname, Prename etc) behind it.
Private Sub cmb_Format (...) Handles cmb.Format
e.ListItem.Value = row.Item("SURNAME") & " " & row.Item("PRENAME")
End Sub
With this method I kind of overwrite the DisplayMember.
The problem is that if I choose one listitem by the Dropdown the textfield writes BOTH (PRENAME and SURNAME) but I just want to have the SURNAME.
I tried several hours, but no success :(
You're not overwriting the DisplayMember you are overwriting the ValueMember.
Do:
e.ListItem.Text = row.Item("SURNAME") & " " & row.Item("PRENAME")