Vb.Net Combobox DisplayMember - vb.net

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")

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,

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.

MS Access: Concatenate two fields into existing field

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

ComboBox.Text to Label.Text

The project is an alarm clock and the comboboxes select the alarm time which i want to print to label4 in the format hr:min:sec AM/PM
i need to copy the value the is selected in my comboboxes and print them into a label with the format hr:min:sec AM/PM. This is what i have:
Label4.Text = (ComboBox1.SelectedText) & ":" & (ComboBox2.SelectedText) & ":"(ComboBox3.SelectedText) & " " & (ComboBox4.SelectedText)
' the rest of the combo boxes are similar
ComboBox1.Items.Add("1")
ComboBox1.Items.Add("2")
ComboBox1.Items.Add("3")
ComboBox1.Items.Add("4")
ComboBox1.Items.Add("5")
ComboBox1.Items.Add("6")
ComboBox1.Items.Add("7")
ComboBox1.Items.Add("8")
ComboBox1.Items.Add("9")
ComboBox1.Items.Add("10")
ComboBox1.Items.Add("11")
ComboBox1.Items.Add("12")
'ComboBox1.SelectedIndex = vari1
ComboBox1.Update()
Just as you said yourself in the title, you should be using Text, not SelectedText. SelectedText is NOT the same as SelectedItem. It's the same as the similarly-named property of a TextBox, i.e. the part of the text that is highlighted. You're also missing an &, but that's not your core issue.

vb2010 combobox automatic change text from items

I am using vb2010 and I have a problem with combobox. My code below get the items from mysql database then add it to the combobox. When there is an item in combobox say for example "NERISON" when I input "N" in the combox and press tab, the combobox will automatically change the text to "NERISON" -what I don't want. I just want to leave it with "N" as text. How would I do that?
If Not e.KeyChar = ChrW(8) Then
txtprice.Text = ""
With cmb_particular
.Items.Clear()
load_dbase() ' connects to database
CNN.Open()
runSql("select particular from particular where status=0 and particular like '%" & .Text & "%' order by particular") ' my function for queries
While dr.Read
.Items.Add(dr("particular"))
End While
CNN.Close()
.SelectionStart = cmb_particular.Text.Length
.DroppedDown = True
End With
End If
Could it be that autofill / autocompelte is enabled in the combobox?
For WPF, set the following:
IsTextSearchEnabled = False
For Forms:
ComboBox.AutoCompleteMode = False
In your combobox properties be sure that AutoCompleteMode=None
#Nerison:
I 've added a comboBox in a form. I don't change anything. I check its properties:
ComboBox1.AutoCompleteMode=None
ComboBox1.AutoCompleteSource=None
ComboBox1.DropDownStyle=DropDown
I add a datatable as datasource. Now I have the bahaviour that you want. I type "N" and it doesn't suggest or append anything.
Could you please check it again?