I made a database in Access 2010 that has a module called Assignments() which contains a few functions. What I want it to do is populate the “Specialist” field (Column A) into the returned results of the select query “qry_live_records_No_Specialist”, based on the Assignment Percentage field defined in column B of the table “tbl_Specialists”.
I am getting Run-time error 3141: The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
I don’t have the skills to debug this (I borrowed the code from another database at work and tweaked it with my own database’s object names). I was hoping someone could help me get this working.
As an alternative, I could drop the entire percentage feature and replace the Assignment Percentage field in “tbl_Specialists” with something to indicate whether to assign records to that specialist, and have it cycle through all included specialists until the last record in the query has had a name added. I don't know how to code it though.
I put the line I get the error on in large red text.
Thanks!
Don
Code:
Function assignNewRecords()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim lngTotUnassign As Long
Dim strSpecialist As String
Dim dblAssnPercent As Double
Dim lngRecsAssign As Long
'***Calculates Total New Unassigned Items***
lngTotUnassign = getTotalUnassigned
'*******************************************
Set db = CurrentDb()
Set rs = db.OpenRecordset("tbl_Specialists", dbOpenDynaset)
With rs
Do Until .EOF
strSpecialist = ![Specialist]
dblAssnPercent = ![Assignment Percentage]
If dblAssnPercent > 0 Then
'***Calculates Number of Items to be Assigned******
lngRecsAssign = lngTotUnassign * dblAssnPercent
'**************************************************
'***Assign Requests********************************
Call updateInitials(lngRecsAssign, strSpecialist)
'**************************************************
Else
lngRecsAssign = 0
End If
.MoveNext
Loop
End With
End Function
Function updateInitials(lngRecsAssign As Long, strSpecialist As String)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
strSQL = "SELECT TOP " & lngRecsAssign & " * " & _
"FROM [qry_live_records_No_Specialist] " & _
"WHERE [Specialist] Is Null "
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
With rs
Do Until .EOF
.Edit
![Specialist] = strSpecialist
.Update
.MoveNext
Loop
End With
End Function
Function getTotalUnassigned() As Long
getTotalUnassigned = DCount("[BIS ID]", "qry_live_records_No_Specialist")
End Function
Function percentageAssigned() As Double
percentageAssigned = DSum("[Assignment Percentage]", "tbl_Specialists")
End Function
qry_live_records_No_Specialist:
Specialist |
BIS ID |
|
1395576 |
|
1395580 |
|
1395581 |
|
1395582 |
tbl_Specialists:
Specialist |
Assignment Percentage |
John |
0.25% |
Mary |
0.25% |
Lucy |
0.50% |
Henry |
0.00% |