Two ComboBoxes to search data in a table. One to Select ITEM y the other DIAMETRO. The first search data strings and later to search numbers.
Private Sub cmdShowData_Click()
'populate data
strSQL = "SELECT * FROM [data$] WHERE "
If cmbItem.Text <> "" Then
strSQL = strSQL & " [ITEM]='" & cmbItem.Text & "'"
End If
If cmbDiametro.Text <> "" Then
If cmbItem.Text <> "" Then
strSQL = strSQL & " AND [DIAMETRO]= " & cmbDiametro.Value
Else
strSQL = strSQL & " [DIAMETRO]='" & cmbDiametro.Value & ""
End If
End If
If cmbItem.Text <> "" Or cmbDiametro.Text <> "" Then
'now extract data
closeRS
OpenDB
error à rs.Open strSQL, cnn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
Sheets("View").Visible = True
Sheets("View").Select
Range("dataSet").Select
Range(Selection, Selection.End(xlDown)).ClearContents
'Now putting the data on the sheet
ActiveCell.CopyFromRecordset rs
Else
MsgBox "I was not able to find any matching records.", vbExclamation + vbOKOnly
Exit Sub
End If
End If
End Sub
The above subroutine works fine for integers in DIAMETRO but for decimals (ex 0,75) gives the following error:
A runtime error occurred -2147217900 (80040e14):
[Microsoft] [Controller] ODBC Excel] Syntax error (comma) in the query expression '' [ITEM] ='TUBERIA' AND [DIAMETER] = 0,75. '
Note: I declared Public strSQL As Variant
I will thanks any help to solve this situation.
Private Sub cmdShowData_Click()
'populate data
strSQL = "SELECT * FROM [data$] WHERE "
If cmbItem.Text <> "" Then
strSQL = strSQL & " [ITEM]='" & cmbItem.Text & "'"
End If
If cmbDiametro.Text <> "" Then
If cmbItem.Text <> "" Then
strSQL = strSQL & " AND [DIAMETRO]= " & cmbDiametro.Value
Else
strSQL = strSQL & " [DIAMETRO]='" & cmbDiametro.Value & ""
End If
End If
If cmbItem.Text <> "" Or cmbDiametro.Text <> "" Then
'now extract data
closeRS
OpenDB
error à rs.Open strSQL, cnn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
Sheets("View").Visible = True
Sheets("View").Select
Range("dataSet").Select
Range(Selection, Selection.End(xlDown)).ClearContents
'Now putting the data on the sheet
ActiveCell.CopyFromRecordset rs
Else
MsgBox "I was not able to find any matching records.", vbExclamation + vbOKOnly
Exit Sub
End If
End If
End Sub
The above subroutine works fine for integers in DIAMETRO but for decimals (ex 0,75) gives the following error:
A runtime error occurred -2147217900 (80040e14):
[Microsoft] [Controller] ODBC Excel] Syntax error (comma) in the query expression '' [ITEM] ='TUBERIA' AND [DIAMETER] = 0,75. '
Note: I declared Public strSQL As Variant
I will thanks any help to solve this situation.