So here's the thing; I'm making this home-made sign-up thing for a school project.
I've got first name, last name, date of birth, SS number among other things.
I can send data to another form's listbox
Dim SSID = (tx_SSP.Text)
Datbase_of_User_Information.ListBox1.Items.Add(SSID)
However this will only add ONE item to the listbox. I know there's a way to add in a multi-column data thing into the list
ex:
SSID | Fname | Lname | DoB
Something like the above.
But I've tried doing Listbox1.AddItem("row1 col1", SSID)
and it didn't work.
I had this same problem and I kind of cheated by just putting all the values together into one string and using tabs.
Listbox1.Items.Add(SSID & " " & Fname & " " & Lname & " " & DoB)
I've heard a better solution would be to use a ListView if you want a true multi-column solution.
Related
I am working with two forms and their corresponding tables in ms access : Warranty (WarrantyDetail) and Findings(Findings). The only common field between these 2 forms is the CODE field which states the code for the PID number of the product in the warranty detail table.
When a user enters a date code in the warranty form, and if the corresponding entry in the Findings form has a FixDate which is less than the DateCode, I want to display a msgbox. I am doing this by comparing the values in the tables of these forms. However, it does not seem to work so far. Following is the code:
Dim Fdate
Dim FCode
FCode = DLookup("FINDINGS", "WarrantyDetail", "RGA =" & Me.RGA)
Fdate = DLookup("[FixDate]", "[Findings]", "Code =" & FCode)
'FCode = "Select WarrantyDetail.FINDINGS from WarrantyDetail where WarrantyDetail.RGA = '" + Me.RGA + "';"
'Fdate = "Select Findings.[FixDate] from Findings where Findings.[FindingsID]= '" + FCode + "';"
If Not IsNull(Fdate) Then
If (DateValue(Me.DATECODE) > DateValue(Fdate)) Then
MsgBox "The Fixdate precedes the Datecode"
End If
End If
I am using the afterupdate event property on the DATECODE field. And looking for the fixdate for the entry which has the code same as Fcode which is obtained using another statement which looks for a code with the same RGA no. as the one which is present on the form currently. If this makes sense, please give me some pointers.
Fields in the Findings table
Fields in the warrantydetail table
I have a multiple item form which displays client records, e.g., first and last name, date of birth, address, etc… The same client can be listed multiple times in multiple ways and may have the same or similar name as other clients (because bad historic data process). Jim Smith, James Smith, and Jim Smith Jr. could be the same or more than three different people (with date of birth and other information helping to resolve such issues).
I have set up two combo boxes to filter the form sequentially, but I need some help getting them to function as desired. The first combo pulls the list of distinct last names from the underlying table via a simple select query. Once a name is selected the second combo box offers the set of distinct first names with the selected last name.
Is there a way to use the selected last name plus wildcards in the vba so that selecting “Smith” would also return “Smith Jr.”, “Smith-Jones”, and “Smithers”? Right now I have the following which requeries the second combobox and sets the initial filter on the form, at the moment only to “Smith” in my example:
Private Sub cboFindLast_AfterUpdate()
Me.cboFindFirst.Requery
Me.cboFindFirst = Null
Me.Filter = "LName = '" & Me.cboFindLast & "'"
Me.FilterOn = True
End Sub
This works as desired except for not returning the “Smith+” entries. At this point the user can select from cboFindFirst to reduce the list even more. Again, it would be nice if selecting “Ann” would return Ann, Anna, Annie, and even Ruth-Ann if any of those occur. The code currently on the second box is:
Private Sub cboFindFirst_AfterUpdate()
Me.Filter = "FName = '" & Me.cboFindFirst & "' And LName = '" & Me.cboFindLast & "'"
Me.FilterOn = True
End Sub
Again, this works well and reduces the list to e.g., all of the “Ann Smith” records, but maybe there’s a more recent “Annie Smith-Jones” after she was married and I’d like that record to show as well.
Of course, use LIKE with wildcard:
Me.Filter = "LName LIKE '" & Me.cboFindLast & "*'"
Me.Filter = "FName LIKE '" & Me.cboFindFirst & "*' And LName LIKE '" & Me.cboFindLast & "*'"
i want to filter a datagridview in visual basic using two columns at one time. for ex: i want to filter subject column and last name column,
im currently using this code:
me.studentbindingsource.filter = "Subject_code like '%" & ComboBox1.Text & "%'"
but it only filter one at a time.
Use String.Format,
me.studentbindingsource.filter = String.Format("Subject_code like '{0}**' and Last_name like '{1}*'",Combobox1.text,strLastname)
My project is a small Access database with two tables. The first table is "EMPLOYEES" and the second table is "TOOLS". The database keeps track of what specific tools each employee has in his/her possession. My Visual Basic form adds and deletes employees from the database via the dataset.
What I would like to do is set a variable to hold the Employees full name taken from two different fields. (The "FirstName" field and the "LastName" field)
How do I reference (or get the value of) the "FIRST_NAME" and "LAST_NAME" data stored in the "EMPLOYEE" table so that I can set my Visual Basic string Variable with those two values.
Is this a job for SQL?
Something like this:
For i As int32 = 0 To myDATABASE.EMPLOYEES.column.Length
Dim fullName As String = _
myDATABASE.EMPLOYEES.row(i).FIRST_NAME _
& " " & _
MyDATABASE.EMPLOYEES.row(i).LAST_NAME
mylistBox.add("The full name is: " & fullName)
Next
If you are trying to populate a listbox with names, then you can set the recordsource to something like:
Select [First_Name] & " " & [Last_Name] as FullName from Employees
You can concatenate the names in sql as Wayne G. Dunn suggests or you can also do it in vb like this:
For i As Int32 = 0 To MyDATABASE.Tables("EMPLOYEES").Rows.Count - 1
Dim fullName As String = _
MyDATABASE.Tables("EMPLOYEES").Rows(i).Item("FIRST_NAME").ToString() _
& " " & _
MyDATABASE.Tables("EMPLOYEES").Rows(i).Item("LAST_NAME").ToString()
mylistBox.add("The full name is: " & fullName)
Next
For something as simple as putting two strings together it's really a matter of personal preference and it's good to know both ways.
I have a problem very similar to this one, but I just can't seem to solve it!
In MS Access (2003), I want to search a table based on entries in a number of fields, some of which may be empty.
I have:
text fields
date fields
integer fields, and
a memo field (but we can probably not bother searching this one if it is difficult).
They map onto a table exactly.
I am trying to create a query that will return matching rows when data is entered into one or more of these fields, but some fields can be left blank. How the heck do I do this?
A query like the one on the linked question works for text fields, but what do I do about the number fields, date fields (and possibly even the memo field)?
To give a clear example, the following code block works for TextField1, but not NumberField1:
PARAMETERS [Forms]![SearchForm]![FilterTextField1] Text ( 255 ), [Forms]![SearchForm]![FilterNumberField1] Text ( 255 );
SELECT Table1.[TextField1], Table1.[NumberField1], Table1.[TextField2], Table1.[TextField3], Table1.[DateField1], Table1.[DateField2], Table1.[DateField3]
FROM Table1
WHERE (Len([Forms]![SearchForm]![FilterTextField1] & '')=0 OR Table1.[TextField1] Like '*' & [Forms]![SearchForm]![FilterTextField1] & '*') AND (Len([Forms]![SearchForm]![FilterNumberField1] & '')=0 OR Table1.[NumberField1] Like '*' & [Forms]![SearchForm]![FilterNumberField1] & '*');
I do hope you can help. I'm sure I'm missing something really obvious, but for some reason my brain feels like it is leaking out of my ears at the moment.
Thank you!
If you need it, this is the basic design of the relevant entities:
Table1
SomePrimaryKeyWeDontCareAboutRightNow
TextField1
TextField2
TextField3
NumberField1
DateField1
DateField2
DateField3
MemoField1
SearchForm
FilterTextField1
FilterTextField2
FilterTextField3
FilterNumberField1
FilterDateField1
FilterDateField2
FilterDateField3
FilterMemoField1
You can check fo null values or cast to string
You could certainly spend a great deal of time crafting a huge and very hard to debug SQL query for this, or just jump into VBA and write some code to construct just the SQL you need.
VBA is there just for these kinds of scenario, where something is either impossible or becoming too complex to do otherwise.
With VBA, you can use an initial SELECT query that collect all the data, and then construct a WHERE clause based on the content of your search form to filter it.
For instance, I have a form like this, that allows the user to enter any criteria to filter a list of prices:
Some code to implement this could look like:
' Call this whenever the use click the Apply button '
Private Sub btApply_Click()
' Construct the filter '
Dim filter As String
If Not IsBlank(cbSupplierID) Then
If Not IsBlank(filter) Then filter = filter & " AND "
filter = filter & "(SupplierID=" & cbSupplierID & ")"
End If
If Not IsBlank(txtPartNumber) Then
If Not IsBlank(filter) Then filter = filter & " AND "
filter = filter & "(PartNumber LIKE '*" & txtPartNumber & "*')"
End If
If Not ckShowLocked Then
If Not IsBlank(filter) Then filter = filter & " AND "
filter = filter & "(NOT PriceLocked)"
End If
' ... code snipped, you get the jest ... '
' Now re-construct the SQL query '
Dim sql As String
sql = "SELECT * FROM Price"
If Not IsBlank(filter) Then
sql = sql & " WHERE " & filter
End If
SubForm.Form.RecordSource = sql
End Sub
It may seem like a lot of code, but each block only does one thing, and it's a lot easier to debug and maintain than cramming everything into a query.