SQL query to subform

calvinle

Registered User.
Local time
Today, 13:01
Joined
Sep 26, 2014
Messages
332
Hi,

I don't know where is the issue but I am having issue to display the result in my subform using the following query:

Can anyone help on it?

Code:
  Dim strWhere As String              
  Dim rsResult As Recordset
  
  strWhere = "SELECT * FROM tblWork WHERE client_id = " & Nz(Me.cboClient.Value)
  
  Set rsResult = CurrentDb.OpenRecordset(strWhere, dbOpenSnapshot)
  
  Me.frmWork.SourceObject = "sfWork"
  Set Me.frmWork.Form.Recordset = rsResult

The SQL string shows:
Code:
SELECT * FROM tblWork WHERE client_id = "1A1"

but the subform does not display any data.

Thanks
 
Perhaps:

Code:
Me.frmWork.Form.Recordset = "SELECT * FROM tblWork WHERE client_id = " & Nz(Me.cboClient.Value)
 
Client_id is a string so you need text delimiters

Code:
  "SELECT * FROM tblWork WHERE client_id = '" & Nz(Me.cboClient.Value) & "'"
 
Client_id is a string so you need text delimiters

Code:
  "SELECT * FROM tblWork WHERE client_id = '" & Nz(Me.cboClient.Value) & "'"

Finally it works!!

But I though both can work because it's string..? Either " or '
 
What you had would have worked if the field was a number but not for text
 
This is my main code that I use during that filtering:

Code:
strWhere = strWhere & "([client_id] Like ""*" & Me.cboClientId & "*"") AND "

How should I change this one so it works?

Thanks
 

Users who are viewing this thread

Back
Top Bottom