davman2002
Programmer
Ok I have been charged with producing a report that will be emailed to the Physicians at my company. The way they want the report to appear is as follows.
Doctor Results
Dr1 1.0
Dr2 2.0
Dr3 3.0
Real Dr Name 4.0
Dr5 5.0
Dr6 6.0
They want the physician to be able to see at which place their results fall but they do not want that physician to be able to see the names of the other physicians wither above or below their name. I have created code that I thought should work unfortuniately it does not. I keep getting one error on the line that states
Set rst2 = dbs.OpenRecordset(strSQL2)
Can someone help Here is my code.
Function test()
Dim dbs As DATABASE
Dim rst As Recordset
Dim rst2 As Recordset
Dim strSQL2 As String
Dim strSQL As String
Dim Current_DEA As String
Dim New_Dr_Name As String
Dim Table_Name As String
Dim counter As Integer
' Return reference to current database.
Set dbs = CurrentDb
' Select record to be updated
strSQL = "SELECT DEA_NUMBER FROM Formulary ;"
Set rst = dbs.OpenRecordset(strSQL)
counter = 0
While Not rst.EOF
Current_DEA = rst("DEA_NUMBER"
counter = counter + 1
New_Dr_Name = "Dr" & counter
DoCmd.DeleteObject acTable, "TEMP_TABLE"
DoCmd.OpenQuery "500 Create Temp_Table"
strSQL2 = "UPDATE TEMP_TABLE " & _
"SET TEMP_TABLE.Physician = '" & New_Dr_Name & "'" & _
"WHERE (((TEMP_TABLE.DEA_NUMBER)<> '" & Current_DEA & "'));"
DoCmd.RunSQL (strSQL2)
Set rst2 = dbs.OpenRecordset(strSQL2)
rst.MoveNext
Wend
rst.Close
Set dbs = Nothing
Doctor Results
Dr1 1.0
Dr2 2.0
Dr3 3.0
Real Dr Name 4.0
Dr5 5.0
Dr6 6.0
They want the physician to be able to see at which place their results fall but they do not want that physician to be able to see the names of the other physicians wither above or below their name. I have created code that I thought should work unfortuniately it does not. I keep getting one error on the line that states
Set rst2 = dbs.OpenRecordset(strSQL2)
Can someone help Here is my code.
Function test()
Dim dbs As DATABASE
Dim rst As Recordset
Dim rst2 As Recordset
Dim strSQL2 As String
Dim strSQL As String
Dim Current_DEA As String
Dim New_Dr_Name As String
Dim Table_Name As String
Dim counter As Integer
' Return reference to current database.
Set dbs = CurrentDb
' Select record to be updated
strSQL = "SELECT DEA_NUMBER FROM Formulary ;"
Set rst = dbs.OpenRecordset(strSQL)
counter = 0
While Not rst.EOF
Current_DEA = rst("DEA_NUMBER"
counter = counter + 1
New_Dr_Name = "Dr" & counter
DoCmd.DeleteObject acTable, "TEMP_TABLE"
DoCmd.OpenQuery "500 Create Temp_Table"
strSQL2 = "UPDATE TEMP_TABLE " & _
"SET TEMP_TABLE.Physician = '" & New_Dr_Name & "'" & _
"WHERE (((TEMP_TABLE.DEA_NUMBER)<> '" & Current_DEA & "'));"
DoCmd.RunSQL (strSQL2)
Set rst2 = dbs.OpenRecordset(strSQL2)
rst.MoveNext
Wend
rst.Close
Set dbs = Nothing