Problem with code

ds0203

Registered User.
Local time
Yesterday, 23:12
Joined
Feb 22, 2007
Messages
14
Greetings - I have this code that I pulled from another project and just changed the table/field names to match my current project, but when I try to run the code I keep getting an error that too few parameters are expected or a problem with the from clause. Can someone identify my error?

Thanks,
ds


Sub ProcessUnitPaste()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset, rst2 As DAO.Recordset
Dim strTaskTitle As String, strProcessUnit As String
Dim intNumber As Integer
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT [TaskUploadTemplate].* " & _
"FROM [TaskUploadTemplate]")
rst.MoveFirst
Do While Not rst.EOF
strTaskTitle = rst.Fields("Task Statement")
strTaskTitle = Replace(strTaskTitle, "'", "''")
Set rst2 = dbs.OpenRecordset("SELECT [Task Process Units].[Process Unit], " & _
"tblTasks.[Task Statement] FROM tblTasks INNER JOIN " & _
"[Task Process Units] ON " & _
"tblTasks.TaskID = [Task Process Units].[TaskID] " & _
"WHERE (((tblTasks.[Task Statement])='" & strTaskTitle & "'))")
If rst2.RecordCount > 0 Then rst2.MoveFirst
intNumber = 1

Do While Not rst2.EOF

strProcessUnit = Nz(rst2.Fields("Process Unit"), "")

rst.Edit
rst.Fields("Process Unit " & intNumber) = strProcessUnit
rst.Update

intNumber = intNumber + 1

rst2.MoveNext
Loop
strTaskTitle = Replace(strTaskTitle, "''", "'")
rst.MoveNext

Loop
End Sub
 
Most likely cause is a misspelled column name (or tablename). Set breakpoints in your code as to capture the SQL strings in the Immediate Window. Then paste the strings into SQL view as to run the query from there. You will see a messagebox asking you for a parameter, if your string has a column name not found in the tables or misspelled.
 

Users who are viewing this thread

Back
Top Bottom