merciless32
Registered User.
- Local time
- Today, 18:26
- Joined
- Mar 4, 2002
- Messages
- 48
Please help. I have a table that contains a user ID and question numbers. Each user can have multiple questions assigned to them. This script is supposed to take the user ID and combine all questions on a single line seperated by "|". For instance...
User Question
A111 A1
A111 A2
A111 A3
...needs to return...
User Question
A111 A1|A2|A3
Please let me know what I am doing wrong if you can. Thanks in advance.
------------------------------
Function Update()
On Error GoTo ErrorHandler
Dim dbs As Database
Dim rsOrigin, rsDestination As Recordset
Dim strPrimaryQuestion, strQuestion As String
Dim strObserver As String
Dim bSuccess As Boolean
'Sets tables and variables
Set dbs = CurrentDb
Set rsOrigin = dbs.OpenRecordset("Observer_Questions")
Set rsDestination = CurrentDb.OpenRecordset("Observer Questions")
strObserver = rsOrigin.Fields("Observer")
strQuestion = rsOrigin.Fields("Question_Number")
If Not rsOrigin.EOF() Then
rsOrigin.MoveNext
End If
'Sets Actions
Do While Not rsOrigin.EOF()
strPrimaryQuestion = strPrimaryQuestion & "|" & strQuestion
If rsOrigin.Fields("Observer") <> strObserver Then
'Add Records to Observer Question table
rsDestination.AddNew
rsDestination.Fields("Observer") = strObserver
rsDestination.Fields("Question_Number") = strPrimaryQuestion
rsDestination.Update
strObserver = rsOrigin.Fields("Observer")
strQuestion = rsOrigin.Fields("Question_Number")
strPrimaryQuestion = ""
Else
strQuestion = rsOrigin.Fields("Question_Number")
End If
rsOrigin.MoveNext
Loop
rsDestination.AddNew
rsDestination.Fields("Observer") = strObserver
rsDestination.Fields("Question_Number") = strQuestion
rsDestination.Update
bSuccess = True
'Final actions and messages
If bSuccess = True Then
MsgBox "All Records Updated Sucessfully!"
End If
Exit Function
'Error message
ErrorHandler:
MsgBox "Unhandled error #" + CStr(Err.Number) + "-" + Err.Description
End Function
User Question
A111 A1
A111 A2
A111 A3
...needs to return...
User Question
A111 A1|A2|A3
Please let me know what I am doing wrong if you can. Thanks in advance.
------------------------------
Function Update()
On Error GoTo ErrorHandler
Dim dbs As Database
Dim rsOrigin, rsDestination As Recordset
Dim strPrimaryQuestion, strQuestion As String
Dim strObserver As String
Dim bSuccess As Boolean
'Sets tables and variables
Set dbs = CurrentDb
Set rsOrigin = dbs.OpenRecordset("Observer_Questions")
Set rsDestination = CurrentDb.OpenRecordset("Observer Questions")
strObserver = rsOrigin.Fields("Observer")
strQuestion = rsOrigin.Fields("Question_Number")
If Not rsOrigin.EOF() Then
rsOrigin.MoveNext
End If
'Sets Actions
Do While Not rsOrigin.EOF()
strPrimaryQuestion = strPrimaryQuestion & "|" & strQuestion
If rsOrigin.Fields("Observer") <> strObserver Then
'Add Records to Observer Question table
rsDestination.AddNew
rsDestination.Fields("Observer") = strObserver
rsDestination.Fields("Question_Number") = strPrimaryQuestion
rsDestination.Update
strObserver = rsOrigin.Fields("Observer")
strQuestion = rsOrigin.Fields("Question_Number")
strPrimaryQuestion = ""
Else
strQuestion = rsOrigin.Fields("Question_Number")
End If
rsOrigin.MoveNext
Loop
rsDestination.AddNew
rsDestination.Fields("Observer") = strObserver
rsDestination.Fields("Question_Number") = strQuestion
rsDestination.Update
bSuccess = True
'Final actions and messages
If bSuccess = True Then
MsgBox "All Records Updated Sucessfully!"
End If
Exit Function
'Error message
ErrorHandler:
MsgBox "Unhandled error #" + CStr(Err.Number) + "-" + Err.Description
End Function