Hi all.
Found out that I want to go from linked tabled on sql server backend to sql connections within code.
I've got a test up and running, but struggling with sql queries which are getting the Where criteria from the forms combo boxes.
The actual SQL Query is:
strSql = "SELECT dbo.UserLog.ID, dbo.UserLog.UserProjectNo, dbo.UserLog.UserEmail, dbo.UserReg.EmpName, dbo.UserReg.EmpLevelA, " _
& "dbo.UserLog.UserIn, dbo.UserLog.UserOut " _
& "FROM dbo.UserReg INNER JOIN dbo.UserLog ON dbo.UserReg.EmpEmail = dbo.UserLog.UserEmail " _
& "WHERE (((dbo.UserLog.UserProjectNo) Like '*' & [Forms]![CableAdminTool]![NavigationSubform].[Form]![cboSelectProject] & '*') " _
& "AND ((dbo.UserLog.UserEmail) Like '*' & [Forms]![CableAdminTool]![NavigationSubform].[Form]![cboSelectUserEmail] & '*'))" _
& "ORDER BY dbo.UserLog.ID"
First, on linked tables, all references to the linked tables where dbo_ Testing with a simple query I found that I need to remove the _ and replace it with .
But, when adding the Where clause, I'm really stuck (Of course, this query works fine with linked table, but with dbo_ etc).
I've replaces the & [Forms..... ]![cboSelectProject] with any version I can come up with, including using Me.cboSelectProject, and also getting value from the combobox to a variable, and put the text variable into the Query with '" & [txtVariable] & "'. Also testet both type with all kinds of different setup wit single and double quota...
The error message have been Error near ' or ! or &, Error due to mismatch, and error due to varchar mismatch (Btw, text column in sql table are nvarchar(nn)).
What is it I am missing or doing wrong?
To prove the connection work, the image is without the WHERE in the query string above...
Edit: Yes, I'm using navigation form as main form with subforms.
And yes, I'm almost always make queries with the Query Designer so I'm sure it works before I copy sql code into forms/reports where that is most convenient. But for the same reason I want to stop using linked tables, I also want to hardcode queries into forms/reports which today are around 50% as separate queries and 50% hardcoded in forms/reports.
Thank you!
Best regards, Geirr.
Found out that I want to go from linked tabled on sql server backend to sql connections within code.
I've got a test up and running, but struggling with sql queries which are getting the Where criteria from the forms combo boxes.
The actual SQL Query is:
strSql = "SELECT dbo.UserLog.ID, dbo.UserLog.UserProjectNo, dbo.UserLog.UserEmail, dbo.UserReg.EmpName, dbo.UserReg.EmpLevelA, " _
& "dbo.UserLog.UserIn, dbo.UserLog.UserOut " _
& "FROM dbo.UserReg INNER JOIN dbo.UserLog ON dbo.UserReg.EmpEmail = dbo.UserLog.UserEmail " _
& "WHERE (((dbo.UserLog.UserProjectNo) Like '*' & [Forms]![CableAdminTool]![NavigationSubform].[Form]![cboSelectProject] & '*') " _
& "AND ((dbo.UserLog.UserEmail) Like '*' & [Forms]![CableAdminTool]![NavigationSubform].[Form]![cboSelectUserEmail] & '*'))" _
& "ORDER BY dbo.UserLog.ID"
First, on linked tables, all references to the linked tables where dbo_ Testing with a simple query I found that I need to remove the _ and replace it with .
But, when adding the Where clause, I'm really stuck (Of course, this query works fine with linked table, but with dbo_ etc).
I've replaces the & [Forms..... ]![cboSelectProject] with any version I can come up with, including using Me.cboSelectProject, and also getting value from the combobox to a variable, and put the text variable into the Query with '" & [txtVariable] & "'. Also testet both type with all kinds of different setup wit single and double quota...
The error message have been Error near ' or ! or &, Error due to mismatch, and error due to varchar mismatch (Btw, text column in sql table are nvarchar(nn)).
What is it I am missing or doing wrong?
To prove the connection work, the image is without the WHERE in the query string above...
Edit: Yes, I'm using navigation form as main form with subforms.
And yes, I'm almost always make queries with the Query Designer so I'm sure it works before I copy sql code into forms/reports where that is most convenient. But for the same reason I want to stop using linked tables, I also want to hardcode queries into forms/reports which today are around 50% as separate queries and 50% hardcoded in forms/reports.
Thank you!
Best regards, Geirr.
Last edited: