I'm sorry,Now the code return a error message..
Run Time error 2176 :
"The setting for this property is too long"
and highlight
Me.RecordSource = strSQL
I don't remove the criteria on the actual query.And it seem the criteria
don't
work at all,cause the form return all records,and it seem some another
code
become not work properly.
Here is the excatly what I've wrote in my vba window code :
Dim strSQL As String
Dim strWhere As String
Const cstrStub = " SELECT [Inspection result_tbl].Model, [Model
specification_tbl].[Rotation speed No]," _
& "[Model specification_tbl].Customer, [Model specification_tbl].[Remark
free air current spec_1]," _
& "[Model specification_tbl].[Free air current lo limit_1], [Model
specification_tbl].[Free air current hi limit_1]," _
& "[Model specification_tbl].[Remark rotation speed spec_1], [Model
specification_tbl].[Rotation speed lo limit_1]," _
& "[Model specification_tbl].[Rotation speed hi limit_1], [Model
specification_tbl].[Remark lock current spec_1]," _
& "[Model specification_tbl].[Lock current lo limit_1], [Model
specification_tbl].[Lock current hi limit_1]," _
& "[Model specification_tbl].[Remark free air current spec_2], [Model
specification_tbl].[Free air current lo limit_2]," _
& "[Model specification_tbl].[Free air current hi limit_2], [Model
specification_tbl].[Remark rotation speed spec_2]," _
& "[Model specification_tbl].[Rotation speed lo limit_2], [Model
specification_tbl].[Rotation speed hi limit_2]," _
& "[Model specification_tbl].[Remark lock current spec_2], [Model
specification_tbl].[Lock current lo limit_2]," _
& "[Model specification_tbl].[Lock current hi limit_2], [Inspection
result_tbl].[Inspection date]," _
& "[Inspection result_tbl].[Input date], [Inspection result_tbl].[Lot no],
[Inspection result_tbl].[Input voltage]," _
& "([Input voltage]*[Current_1]) AS WattCurr1, [Inspection
result_tbl].Current_1, [Inspection result_tbl].RPM_1, " _
& "([Input voltage]*[Lock current_1]) AS WattLockCurr1, [Inspection
result_tbl].[Lock current_1]," _
& "([Input voltage]*[Current_2]) AS WattCurr2, [Inspection
result_tbl].Current_2, [Inspection result_tbl].RPM_2," _
& "([Input voltage]*[Lock current_2]) AS WattLockCurr2, [Inspection
result_tbl].[Lock current_2]," _
& "[Inspection result_tbl].Judge, [Inspection result_tbl].Inspector" _
& "FROM [Model specification_tbl] RIGHT JOIN [Inspection result_tbl] ON
[Model specification_tbl]." _
& "Model = [Inspection result_tbl].Model"
Const cstrTail = " ORDER BY [Inspection result_tbl].[Input date];"
strWhere = "WHERE ((([Inspection result_tbl].Model)=" _
& "[Forms]![Find data_frm]![list_Model]) " _
& "AND (([Inspection result_tbl].[Inspection date])=" _
& "[Forms]![Find data_frm]![list_InspectionDate]) " _
& "AND (([Inspection result_tbl].[Lot no])=" _
& "[Forms]![Find data_frm]![list_Lotno])) "
'add to strWhere
If Me.Password_txt.Value = "123" Then
Me.cmd_Edit.Visible = True
strWhere = strWhere & "AND (([Inspection result_tbl].Judge)=""OK""))
"
Else
Me.cmd_Edit.Visible = False
End If
strSQL = cstrStub & strWhere & cstrTail
Debug.Print strSQL
'it's highlighted the below line
Me.RecordSource = strSQL
Douglas J. Steele said:
You can't put double quotes inside of double quotes like that. You either
need to double up on the double quotes inside (that's a confusing
sentence
isn't it! <g>):
strWhere = strWhere & "AND (([Inspection result_tbl].Judge)=""OK"")) "
or use single quotes as the delimiter inside the string:
strWhere = strWhere & "AND (([Inspection result_tbl].Judge)='OK')) "
--
Doug Steele, Microsoft Access MVP
(no private e-mails, please)
Dear Ms Jeanette and Mr Allen
I've got syntax error on below line
strWhere = strWhere & "AND (([Inspection result_tbl].Judge)="OK")) "
and how to add one more line of below statement
to the vba code window;
FROM [Model specification_tbl] RIGHT JOIN [Inspection result_tbl] ON
[Model
specification_tbl].Model = [Inspection result_tbl].Model
Sorry if my question disturbing you and Thank's for the help.
In the form's load event put code something like this:
make sure to leave a single space between the end of the select clause
and
the following double quote character
Note: there is a single space between the end of strWhere and the
following
double quote character
------------------
Dim strSQL as String
Dim strWhere as String
const cstrStub = "your select part of the query here"
const cstrTail = "ORDER BY ..."
strWhere = "WHERE ((([Inspection result_tbl].Model)=" _
& "[Forms]![Find data_frm]![list_Model]) " _
& "AND (([Inspection result_tbl].[Lot no])=" _
& "[Forms]![Find data_frm]![list_Lotno])) "
If Me.txtUser = "A" Then
'do nothing here, there is nothing to add to strWhere
ElseIf Me.txtUser = "B" Then
strWhere = strWhere & "AND (([Inspection
result_tbl].Judge)="OK"))
"
Else
'anything else you may need here
End If
strSQL = cstrStub & strWhere & cstrTail
Debug.Print strSQL
Me.RecordSource = strSQL
---------------------
replace txtUser, A, B , your select part of the query here, ORDER BY ...
with the appropriate things on your form.
Jeanette Cunningham
Hi All,
I want to be able to switch of the query criteria of my form record
source,
depending on the user name.May be On Load even of my form wee need
to write some code but I always fail.
Please help:
If the user is A then the query's criteria is :
WHERE ((([Inspection result_tbl].Model)=[Forms]![Find
data_frm]![list_Model])
AND (([Inspection result_tbl].[Lot no])=[Forms]![Find
data_frm]![list_Lotno]))
And if the user is B the query's criteria is :
WHERE ((([Inspection result_tbl].Model)=[Forms]![Find
data_frm]![list_Model])
AND (([Inspection result_tbl].[Lot no])=[Forms]![Find
data_frm]![list_Lotno])
AND (([Inspection result_tbl].Judge)="OK"))
Thank's