I have a form with multiple combo boxes that opens a report according to the values in my combo boxes. This works but I was asked to give an option to the Effective Date field so a date range can be entered.
I added two text boxes (txtReqCreationStartDate and txtReqCreationEndDate) for beginning and ending.
I tried doing the between...and in the query but then my combo boxes don't work.
I never used SQL but found this online and entered it in the code for the Apply Filter on click button but I get all of the records. Others have tried to help but I always get all the records.
Here is all of the code for the On Click event.
Private Sub cmdVacanciesWithNoRequisitionParameters_Click()
On Error GoTo cmdVacanciesWithNoRequisitionParameters_Click_Err
strSQL = "SELECT * FROM qryVacanciesWithNoRequisition WHERE " _
& "DateValue([Effective Date]) Between #" & Format([txtReqCreationStartDate], "yyyy-mm-dd") & "# And #" & Format([txtReqCreationEndDate], "yyyy-mm-dd") & "#;"
'Person Number
If Not IsNull(Me.cboPersonNumber) Then
strFilter = strFilter & " AND [Person Number] Like """ & Me.cboPersonNumber & """ "
End If
'Person Name
If Not IsNull(Me.cboPersonName) Then
strFilter = strFilter & " AND [Person Name] Like """ & Me.cboPersonName & """ "
End If
'Job Code
If Not IsNull(Me.cboJobCode) Then
strFilter = strFilter & " AND [Job Code] Like """ & Me.cboJobCode & """ "
End If
'Person Number
If Not IsNull(Me.cboBusinessUnit) Then
strFilter = strFilter & " AND [Business Unit] Like """ & Me.cboBusinessUnit & """ "
End If
'Department
If Not IsNull(Me.cboDepartment) Then
strFilter = strFilter & " AND [Department] Like """ & Me.cboDepartment & """ "
End If
'Supervisor
If Not IsNull(Me.cboSupervisor) Then
strFilter = strFilter & " AND [Supervisor] Like """ & Me.cboSupervisor & """ "
End If
'Job Title
If Not IsNull(Me.cboJobTitle) Then
strFilter = strFilter & " AND [Job Title] Like """ & Me.cboJobTitle & """ "
End If
'If the report is closed, open the report
If SysCmd(acSysCmdGetObjectState, acReport, "rptVacanciesWithNoRequisition") <> acObjStateOpen Then
DoCmd.OpenReport "rptVacanciesWithNoRequisition", acPreview, qryVacanciesWithNoRequisition
End If
'if report was open, use filter
With Reports![rptVacanciesWithNoRequisition]
.Filter = Mid(strFilter, 6)
.FilterOn = True
End With
cmdVacanciesWithNoRequisitionParameters_Click_Exit:
Exit Sub
cmdVacanciesWithNoRequisitionParameters_Click_Err:
MsgBox Error$
Resume cmdVacanciesWithNoRequisitionParameters_Click_Exit
End Sub
Thanks in advance for the help.
It should work for you - you just did a copy/paste without using the same variable name as your filter uses.
Change
strSQL = "SELECT * FROM qryVacanciesWithNoRequisition WHERE " _
& "DateValue([Effective Date]) Between #" & Format(Me.txtReqCreationStartDate, "yyyy-mm-dd") & "# And #" & Format(Me.txtReqCreationEndDate, "yyyy-mm-dd") & "#;"
EDIT - knowing now that Effective Date is a text field
Change it to:
If (IsDate(Me.txtReqCreationStartDate) AND IsDate(Me.txtReqCreationEndDate)) then
strFilter = strFilter & " CDate([Effective Date]) Between #" &
CDate(Me.txtReqCreationStartDate) & "# And #" & _
CDate(Me.txtReqCreationEndDate) & "#"
End If
Related
I need help figuring out why I'm getting this syntax error when trying to run this code in Microsoft Access. I am working on this database for work and have some experience with it, but not a whole lot.
I created a database before the one I'm currently working on and it works fine. It is very similar to the database that I'm working on now, so I just copied it and then renamed the fields and text boxes and everything to match the information that this database will be handling.
Essentially I have a table with the data and then I want a form that has a text box for each field in the table with a subtable of the main table incorporated into the form. The user fills in the text boxes with the information and then either adds it to the table or they can click on a record and edit it or delete it with the corresponding buttons on the form.
Now I'm getting a runtime error '3134': syntax error in INSERT INTO statement when trying to click the add button on one of my forms. This only happens on the add button and consequently the update button if it is set to update, but all of the other buttons work fine.
Here is the code for the new database:
Option Compare Database
Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtICN.Tag & "" = "" Then
'this is for insert new
'add data to table
CurrentDb.Execute "INSERT INTO tblInventory(ICN, manu, model, serial, desc, dateRec, dateRem, dispo, project, AMCA, UL, comments) " & _
" VALUES(" & Me.txtICN & ", '" & Me.txtManu & "', '" & Me.txtModel & "', '" & Me.txtSerial & "', '" & Me.txtDesc & "', '" & Me.txtDateRec & "', '" & Me.txtDateRem & "', '" & Me.txtDispo & "', '" & Me.txtProject & "', '" & Me.txtAMCA & "', '" & Me.txtUL & "', '" & Me.txtComments & "')"
Else
'otherwise (Tag of txtICN store the ICN of item to be modified)
CurrentDb.Execute "UPDATE tblInventory " & _
" SET ICN = " & Me.txtICN & _
", manu = '" & Me.txtManu & "'" & _
", model = '" & Me.txtModel & "'" & _
", serial = '" & Me.txtSerial & "'" & _
", desc = '" & Me.txtDesc & "'" & _
", dateRec = '" & Me.txtDateRec & "'" & _
", dateRem = '" & Me.txtDateRem & "'" & _
", dispo = '" & Me.txtDispo & "'" & _
", project = '" & Me.txtProject & "'" & _
", AMCA = '" & Me.txtAMCA & "'" & _
", UL = '" & Me.txtUL & "'" & _
", comments = '" & Me.txtComments & "'" & _
" WHERE ICN = " & Me.txtICN.Tag
End If
'clear form
cmdClear_Click
'refresh data in list on form
frmInventorySub.Form.Requery
End Sub
Private Sub cmdClear_Click()
Me.txtICN = ""
Me.txtManu = ""
Me.txtModel = ""
Me.txtSerial = ""
Me.txtDesc = ""
Me.txtDateRec = ""
Me.txtDateRem = ""
Me.txtDispo = ""
Me.txtProject = ""
Me.txtAMCA = ""
Me.txtUL = ""
Me.txtComments = ""
'focus on ID text box
Me.txtICN.SetFocus
'set button edit to enable
Me.cmdEdit.Enabled = True
'change caption of button add to Add
Me.cmdAdd.Caption = "Add"
'clear tag on txtICN for reset new
Me.txtICN.Tag = ""
End Sub
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub cmdDelete_Click()
'delete record
'check existing selected record
If Not (Me.frmInventorySub.Form.Recordset.EOF And Me.frmInventorySub.Form.Recordset.BOF) Then
'confirm delete
If MsgBox("Are you sure you want to delete this item?", vbYesNo) = vbYes Then
'delete now
CurrentDb.Execute "DELETE FROM tblInventory " & _
"WHERE ICN =" & Me.frmInventorySub.Form.Recordset.Fields("ICN")
'refresh data in list
Me.frmInventorySub.Form.Requery
End If
End If
End Sub
Private Sub cmdEdit_Click()
'check whether there exists data in list
If Not (Me.frmInventorySub.Form.Recordset.EOF And Me.frmInventorySub.Form.Recordset.BOF) Then
'get data to text box control
With Me.frmInventorySub.Form.Recordset
Me.txtICN = .Fields("ICN")
Me.txtManu = .Fields("manu")
Me.txtModel = .Fields("model")
Me.txtSerial = .Fields("serial")
Me.txtDesc = .Fields("desc")
Me.txtDateRec = .Fields("dateRec")
Me.txtDateRem = .Fields("dateRem")
Me.txtDispo = .Fields("dispo")
Me.txtProject = .Fields("project")
Me.txtAMCA = .Fields("AMCA")
Me.txtUL = .Fields("UL")
Me.txtComments = .Fields("comments")
'store id of item in Tag of txtICN in case ICN is modified
Me.txtICN.Tag = .Fields("ICN")
'change caption of button add to Update
Me.cmdAdd.Caption = "Update"
'disable button edit
Me.cmdEdit.Enabled = False
End With
End If
End Sub
And here is the code for the old database:
Option Compare Database
Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtID.Tag & "" = "" Then
'this is for insert new
'add data to table
CurrentDb.Execute "INSERT INTO tblEquipmentList(equipID, equipDesc, equipManu, equipModelNum, equipSerNum, lastCalDate, calDue) " & _
" VALUES(" & Me.txtID & ", '" & Me.txtDesc & "', '" & Me.txtManu & "', '" & Me.txtModelNum & "', '" & Me.txtSerNum & "', '" & Me.txtLastCalDate & "', '" & Me.txtCalDueDate & "')"
Else
'otherwise (Tag of txtID store the id of equipment to be modified)
CurrentDb.Execute "UPDATE tblEquipmentList " & _
" SET equipID = " & Me.txtID & _
", equipDesc = '" & Me.txtDesc & "'" & _
", equipManu = '" & Me.txtManu & "'" & _
", equipModelNum = '" & Me.txtModelNum & "'" & _
", equipSerNum = '" & Me.txtSerNum & "'" & _
", lastCalDate = '" & Me.txtLastCalDate & "'" & _
", calDue = '" & Me.txtCalDueDate & "'" & _
" WHERE equipID = " & Me.txtID.Tag
End If
'clear form
cmdClear_Click
'refresh data in list on form
frmEquipmentListSub.Form.Requery
End Sub
Private Sub cmdClear_Click()
Me.txtID = ""
Me.txtDesc = ""
Me.txtManu = ""
Me.txtModelNum = ""
Me.txtSerNum = ""
Me.txtLastCalDate = ""
Me.txtCalDueDate = ""
'focus on ID text box
Me.txtID.SetFocus
'set button edit to enable
Me.cmdEdit.Enabled = True
'change caption of button add to Add
Me.cmdAdd.Caption = "Add"
'clear tag on txtID for reset new
Me.txtID.Tag = ""
End Sub
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub cmdDelete_Click()
'delete record
'check existing selected record
If Not (Me.frmEquipmentListSub.Form.Recordset.EOF And Me.frmEquipmentListSub.Form.Recordset.BOF) Then
'confirm delete
If MsgBox("Are you sure you want to delete this piece of equipment?", vbYesNo) = vbYes Then
'delete now
CurrentDb.Execute "DELETE FROM tblEquipmentList " & _
"WHERE equipID =" & Me.frmEquipmentListSub.Form.Recordset.Fields("equipID")
'refresh data in list
Me.frmEquipmentListSub.Form.Requery
End If
End If
End Sub
Private Sub cmdEdit_Click()
'check whether there exists data in list
If Not (Me.frmEquipmentListSub.Form.Recordset.EOF And Me.frmEquipmentListSub.Form.Recordset.BOF) Then
'get data to text box control
With Me.frmEquipmentListSub.Form.Recordset
Me.txtID = .Fields("equipID")
Me.txtDesc = .Fields("equipDesc")
Me.txtManu = .Fields("equipManu")
Me.txtModelNum = .Fields("equipModelNum")
Me.txtSerNum = .Fields("equipSerNum")
Me.txtLastCalDate = .Fields("lastCalDate")
Me.txtCalDueDate = .Fields("calDue")
'store id of equipment in Tag of txtID in case id is modified
Me.txtID.Tag = .Fields("equipID")
'change caption of button add to Update
Me.cmdAdd.Caption = "Update"
'disable button edit
Me.cmdEdit.Enabled = False
End With
End If
End Sub
As you can see, I'm pretty confident that they're pretty much identical except for the field names.
I'm also linking an album of screenshots of the database here: http://imgur.com/a/xLV3Q
Thanks for any help you guys can provide.
The problem may be:
Your new table tblInventory has a column DESC which is a SQL reserved keyword. You have two options:
Drop the column DESC and create a new column with different name OR;
Add brackets to your script like this: INSERT INTO tblInventory([ICN], [manu], [model], [serial], [desc], [dateRec], [dateRem], [dispo], [project], [AMCA], [UL], [comments]).
Please check a full list of SQL reserved keywords: Reserved Keywords-Transact-SQL
I am trying to do a simple insert or update into SQL Server as NULL, not blank. I have seen many references online to just set Field = NULL without quotes but it is still coming up as empty, not NULL. Incredibly frustrating.
This is in classic asp.
If Request.Form("Field") = "" or IsNull(Request.Form("Field")) then
Field = NULL
Else
Field = Request.Form("Field")
End If
sSql="UPDATE [table] SET timestamp = {fn NOW()}," &_
"Field = '" & Field & "'," &_
"WHERE [System] = '" & System & "' and Active = '1'"
If I do this, it proves that it is checking because it puts in a 1.
If Request.Form("Field") = "" or IsNull(Request.Form("Field")) then
Field = 1
Else
Field = Request.Form("Field")
End If
sSql="UPDATE [table] SET timestamp = {fn NOW()}," &_
"Field = '" & Field & "'," &_
"WHERE [System] = '" & System & "' and Active = '1'"
I tried this but get an error 500:
sSql="UPDATE [Table] SET timestamp = {fn NOW()}, Field = "
If IsNull(Field) Then
sSQL = sSQL & "NULL"
Else
sSQL = sSQL & "'" & Field & "'" &_
End If
"NTLogon = '" & UCase(NTLogon) & "'" &_
"WHERE [System] = '" & System & "' and Active = '1'"
When I try this in place of my original code:
Field Assignment:
Field = "NULL" and Field = "'" & Request.Form("Field") & "'"
sSQL:
"Field = " & Field & "," &_
I get "An error occurred on the server when processing the URL."
So yeah, insert rant here about using parameterized queries, blah blah blah... now that's out of everyone's system, could we maybe look at the actual question?
The problem is this:
"Field = '" & Field & "'"
Those ampersands are converting your lovingly-populated vbScript NULL value right back into a string. If you don't want that to happen, you need to explicitly handle the IsNull case.
sSQL = "UPDATE [table] SET timestamp = {fn NOW()}, Field = "
If IsNull(Field) Then
sSQL = sSQL & "NULL"
Else
sSQL = sSQL & "'" & Field & "'"
End If
sSQL = sSQL & " WHERE [System] = '" & System & "' AND Active = '1'"
Note that even if you do this via a parameterized query, you'll need to make sure you're not appending your vbScript NULL value onto a string, because "" & NULL = "".
#pinchetpooche Hello there. I had the same issue and tried the given answer, and also received a 500 error page. I found that #Martha forgot to include the necessary SQL field that is being updated (i.e., "Field"). So I put together some test code, using her solution (i.e., using string concatenation and conditional logic), and executed against an actual database, and this solution works perfectly:
sSQLNullTest = "UPDATE CustomersToCCData SET "
sSQLNullTest = sSQLNullTest & "CustomerID = " & iCustomerID & ", "
If IsNull(x_license_number_state) Or x_license_number_state = "" Then
sSQLNullTest = sSQLNullTest & "CCLicenseState = NULL"
Else
sSQLNullTest = sSQLNullTest & "CCLicenseState = '" & x_license_number_state & "' "
End If
sSQLNullTest = sSQLNullTest & " WHERE CCID = '" & iCCInfoCCID & "'
I use the following code to add, edit data in table with form. All works fine, but there is one field which is in date format. I choose the date in the form with date pick up window, but when it imports it to the table it changes the date format from the UK date format to US.
For example I choose 01/11/2014 (1-nov-2014) in the date pick up window in form, and when I add the records to the table, (what I can see in the subform too) it shows 11/01/2014 (11-jan-2014). When I edit the same record with same form it still shows the 11/01/2014. So basically it changes the day and the month.
I've tried to put like 29/11/2014 then it didn't swap the day and the month. I've checked the region setting in control panel, it shows UK, I've tried to make format in my subform, I added the mm-dd-yyyy format to sql, but non of them helped.
Any idea how could I set this?
Thanks for any help
Option Compare Database
Private Sub cmdAdd_Click()
If Me.txtName.Tag & "" = "" Then
CurrentDb.Execute "INSERT INTO [import]([product name], [QtyImport], [ImportDate])" & _
" VALUES('" & Me.txtName & "'," & Me.txtOrderedQty & ",#" & Me.txtDate & "#)"
Else
CurrentDb.Execute "UPDATE import " & _
" SET [product name] = '" & Me.txtName & "'" & _
", [QtyImport] = " & Me.txtOrderedQty & "" & _
", [ImportDate] = #" & Me.txtDate & "#" & _
" WHERE [product name] = '" & Me.txtName.Tag & "'"
End If
cmdClear_Click
importSubform.Form.Requery
End Sub
Private Sub cmdClear_Click()
Me.txtName = ""
Me.txtOrderedQty = ""
Me.txtDate = ""
Me.txtName.SetFocus
Me.CmdEdit.Enabled = True
Me.CmdAdd.Caption = "Add"
Me.txtName.Tag = ""
End Sub
Private Sub CmdEdit_Click()
If Not (Me.importSubform.Form.Recordset.EOF And Me.importSubform.Form.Recordset.BOF) Then
With Me.importSubform.Form.Recordset
Me.txtName = .Fields("product name")
Me.txtOrderedQty = .Fields("QtyImport")
Me.txtDate = .Fields("ImportDate")
Me.txtName.Tag = .Fields("Product Name")
Me.CmdAdd.Caption = "Update"
Me.CmdEdit.Enabled = False
End With
End If
End Sub
Private Sub cmdExit_Click()
DoCmd.Close
End Sub
First parse the inputed date value to a datetime object then pass it's value to DB.
While binding again get the datetime object from the value in database then parse it to get value in 'dd-mm-yy' format.
Alternatively, you can also use the convert method to get date object from your inputed date value which is in 'dd-mm-yy' format i.e.
convert(date, #inputed, 103)
It will give date object where #inputed is your inputed date value.
Then store it in database and while displaying it again convert it back to 'dd-mm-yy' format using the following function.
convert(varchar, #savedDate, 103)
This line will be modified as follows:
CurrentDb.Execute "INSERT INTO [import]([product name], [QtyImport], [ImportDate])" & _
" VALUES('" & Me.txtName & "'," & Me.txtOrderedQty & ",convert(date, '" & Me.txtDate & "',103)"
I hope this above line is correct, correct if wrong as I work i, in C#.
OK So finally I found out how to format date in VBA. I've changed the "values" line in the cmd add click to the following :
" VALUES('" & Me.txtName & "'," & Me.txtOrderedQty & ",#" & Format(Me.txtDate, "mm/dd/yyyy") & "#)"
So this is the code what is actually working to keep everything in UK date format, bcs I read somewhere that VBA always use US date format, no matter u have set your region etc..
I have created a database in Visual Studio and I am coding with VB.net I have created textboxes and checkboxes to match the fields that each will search when the search button is pressed .
whenever i perform a search using the text boxes and checkbox i get an error.
Item Name , Room , Broken, In Use, floor, are the fields searched by the tehe text in NameSearch, RoomSearch, BrokenSearchare, InUseSearch ,FloorSearchrespectivly ....etc
this is thee code for the search button
Private Sub SearchButton_Click(sender As Object, e As EventArgs) Handles SearchButton.Click
RecordDataGridView.Refresh()
Me.RecordBindingSource.Filter = "[Item Name]= '" & NameSearch.Text & "' And [Room]= '" & RoomSearch.Text & "' And [Make]= '" & MakeSearch.Text & _
"' And [Broken]= '" & BrokenSearch.CheckState & "' And [Replaced]= '" & ReplacedSearch.CheckState & "'And [ID#]= '" & IdentificationNumberSearch.Text & _
"' And [Floor]= '" & FloorSearch.Text & "' And [In Use]= '" & InUseSearch.CheckState & "'"
Me.RecordTableAdapter.Fill(Me.MLGDatabaseDataSet.Record)
RecordDataGridView.Refresh()
End Sub
the error
for example I enter a text into item nameSearch and floorSearch and press search ,no result will be turned up as the other text boxes have no text in them.
Without addressing other issues, such as using a parameterized query to prevent SQL injections or using StringBuilder to more efficiently perform concatenation, I believe your issue may be a missing space in this snippet:
ReplacedSearch.CheckState & "'And [ID#]= '"
if you change this to
ReplacedSearch.CheckState & "' And [ID#]= '"
it may resolve the immediate error. However, you almost certainly have additional logic errors introduced by the OR statement in the middle (you probably want to surround the two clauses that are ORed with parentheses).
I spotted the same thing as #competent_tech. I would set it up this way to make it easier to debug.
Dim strFilter As String = _
"[Item Name]= '" & NameSearch.Text & _
"' And [Room]= '" & RoomSearch.Text & _
"' And [Make]= '" & MakeSearch.Text & _
"' And [Broken]= '" & BrokenSearch.CheckState & _
"' Or [Replaced]= '" & ReplacedSearch.CheckState & _
"' And [ID#]= '" & IdentificationNumberSearch.Text & _
"' And [Floor]= '" & FloorSearch.Text & _
"' And [In Use]= '" & InUseSearch.CheckState & "'"
Debug.Print(strFilter)
RecordBindingSource.Filter = strFilter
Edit: you want to filter only when there are conditions given
'filter string
Dim strFilter As String = ""
'for check boxes you probably want to filter only if checked
If BrokenSearch.CheckState = CheckState.Checked Then strFilter += "And [Broken]= " & BrokenSearch.CheckState & " "
If ReplacedSearch.CheckState = CheckState.Checked Then strFilter += "And [Replaced]= " & ReplacedSearch.CheckState & " "
If InUseSearch.CheckState = CheckState.Checked Then strFilter += "And [In Use]= " & InUseSearch.CheckState & " "
'for text boxes you want to filter only if has text
If IdentificationNumberSearch.Text.Length > 0 Then strFilter += "And [ID#]= '" & IdentificationNumberSearch.Text & "' "
If FloorSearch.Text.Length > 0 Then strFilter += "And [Floor]= " & FloorSearch.Text & " "
If RoomSearch.Text.Length > 0 Then strFilter += "And [Room]= " & RoomSearch.Text & " "
If MakeSearch.Text.Length > 0 Then strFilter += "And [Make]= '" & MakeSearch.Text & "' "
If NameSearch.Text.Length > 0 Then strFilter += "And [Item Name]= '" & NameSearch.Text & "' "
'check to make sure there is at least one condition
If strFilter.Length > 0 Then
'remove the first "And"
strFilter = strFilter.Remove(0, 4)
'output
Debug.Print(strFilter)
'set to filter
RecordBindingSource.Filter = strFilter
End If
Edit: Your error "Cannot perform '=' operation on System.Boolean and System.String" I think the problem is that the filter value has to match the field type.
For strings do this: [Make] = 'stringValue' using single quotes;
For integers do this: [Floor] = 24 without single quotes;
For bit do this: [Broken] = 1 without single quotes;
It looks like Broken, Replaced and In Use are Bit type in the database. And I'm guessing that Floor and Room are Integer.
I'm currently making an Excel function that connects to an SQL server and retrieves data as long as it matches the given criteria.
Public Function VehModelUnitsCount(VehModel As String, fran As String, Site As Integer, SaleType As String, StartDate, EndDate, New As Integer) As Variant
Application.Volatile
If adoCN Is Nothing Then Call SetUpConnection
Set adoRS = New ADODB.Recordset
EvoStartDate = Format(StartDate, "yyyy/mm/dd")
EvoEndDate = Format(EndDate, "yyyy/mm/dd")
strSQL = "SELECT COUNT(*) As RCOUNT FROM CARTYPES RIGHT OUTER JOIN CARS ON CARTYPES.Description = CARS.Type LEFT OUTER JOIN CARS2 ON CARS.[Stock Number] = CARS2.[Stock Number]" & Chr(13)
strSQL = strSQL & "WHERE (CARTYPES.NewSale = " & New & " )" & Chr(13)
strSQL = strSQL & "AND (CARTYPES.Franchise = '" & fran & "')" & Chr(13)
strSQL = strSQL & "AND (CARTYPES.Site = " & Site & ")" & Chr(13)
strSQL = strSQL & "AND (CARTYPES.SaleTypeDesc = '" & SaleType & "')" & Chr(13)
strSQL = strSQL & "AND (CARS2.InvoiceDate BETWEEN '" & StartDate & "' AND '" & EndDate & "')" & Chr(13)
strSQL = strSQL & "AND (CARS.Invoiced = '1')" & Chr(13)
Rem strSQL = strSQL & "AND (CARS.Model = '" & VehModel & "')" & Chr(13)
[THIS ONE] - strSQL = strSQL & "AND (CARS.Model CONTAINS '" & VehModel & "')" & Chr(13)
adoRS.Open strSQL, adoCN, adOpenForwardOnly, adLockReadOnly
VehModelUnitsCount = adoRS.Fields("RCOUNT").Value
adoRS.Close
End Function
The string marked with [THIS ONE] is the one I am struggling with, I need to find out whether or not the cell contains the given string, but apparently using 'CONTAINS' doesn't work.
Any help on completing this would be amazing.
Thank you.
You could try -
strSQL = strSQL & "AND (CARS.Model LIKE '%" & VehModel & "%')" & Chr(13)