VBA SQL syntax problem

atrium

Registered User.
Local time
Tomorrow, 00:08
Joined
May 13, 2014
Messages
348
I'm having trouble including a integer variable into an SQL statement.
If I substitute the variable for the numeric 1, it works as expected.

The code is:-
Code:
    Dim intClientId As Integer
    Dim strSQL As String
    Dim rs As DAO.Recordset
    Dim strWhereStatement As String
    Dim strQryFile As String
    
    intClientId = [Forms]![ViewPrintSendClientFrm]![ClientId]
    Set db = CurrentDb
    strQryFile = "DocumentLibrary"
    strWhereStatement = " WHERE (((DocumentLibrary.MatterId)=0) AND ((DocumentLibrary.Attached)=True) AND ((DocumentLibrary.ClientId)= " & intClientId & " )) ;"
    strQryFileSql = "SELECT * FROM " & strQryFile & strWhereStatement

I'm having trouble with the strWhereStatement line and the variable at the end of the statement (AND ((DocumentLibrary.ClientId)= " & intClientId & " )) ;"

Any help would be appreciated
 
You don't tell if you get an error message, or if the result is not as expected?
What value does intClientId have after the code line?
Code:
intClientId = [Forms]![ViewPrintSendClientFrm]![ClientId]
Are you sure that ClientId is a number field type in the table DocumentLibrary?

Check if the generated SQL string is correct by included a Debug.Print strQryFileSql in your code.
 
Thanks Paul

That really helped.

Atrium
 
Has the issue been solved??
 

Users who are viewing this thread

Back
Top Bottom