Hi there! I've got a bit of a problem with determining the max value in the table. I have a table called "Functions" and a column: "Function_KSW".
There are values as follows:
281A01
421A01
281A02
etc.
I want to get the max value of them but under the condition that first three chars are e.g 281 so the max function will take only max from a narrowed criterion.
The chars are to be selected from combolist in a form.
I have written something like this:
But, unfortunately, I am getting Run Time error 13, Type mismatch.
Don't know what is wrong with it.
I have also come up with this: But also doesn't work- the same error
Any suggestions?
BTW. When I want to find the max by the SQL in the query and based on the value to sort in combolist in the form, sorting doesn't work as well. When the dirtect value (here 281) is written in the code it is working. Seems that those ** stars unable to retrive the vaule from the combolist
There are values as follows:
281A01
421A01
281A02
etc.
I want to get the max value of them but under the condition that first three chars are e.g 281 so the max function will take only max from a narrowed criterion.
The chars are to be selected from combolist in a form.
I have written something like this:
Code:
Private Sub Click1()
Dim max As String
max = DMax("Function_KSW", "Functions", "Function_KSW like " * 281 * "") // here 281 for the test's need
// should be: like " * [Forms]![Form1]!
[ListBox0]*"?
End Sub
Don't know what is wrong with it.
I have also come up with this: But also doesn't work- the same error
Code:
Private Sub Click12()
Dim rs As ADODB.Recordset
Dim strSQL As String
Set rs = New ADODB.Recordset
strSQL = "SELECT Max(Function_KSW) FROM Functions WHERE Function_KSW like " * 281 * ""
rs.Open strSQL, CurrentProject.Connection
result = rs("Funkcja_KSW")
MsgBox result
rs.Close
End Sub
BTW. When I want to find the max by the SQL in the query and based on the value to sort in combolist in the form, sorting doesn't work as well. When the dirtect value (here 281) is written in the code it is working. Seems that those ** stars unable to retrive the vaule from the combolist
Last edited: