Hi,
I’m getting Run Time Error 3705: OPERATION IS NOT ALLOWED WHEN THE OBJECT IS OPEN when I click on a Label Button with code behind it in a MS Access Form I have. I think I found the thing causing Error 3705 within the code below which I believe has to with this variable "rstTakLists" that I created.
</SPAN>
SIDE NOTE: When I click LABEL BUTTON this is what literally happens...
1st: A message window appears that I created and all the User has to do is click on the OK button to continue
2nd: Another message window appears that I created that asks the User a question and the User has the option to click on either the Yes Button or No Button to continue
So when I click the Label button, then the OK button, and then on the No Button I get a window with Run Time Error 3705 and it highlights this VBA code ".Source = strSQLStmt" in yellow thus indicating that this is where the error is occurring. I don’t think the problem is with this VBA code ".Source = strSQLStmt", I think I am getting the Error 3705 because I need to close object “rstTakLists”. </SPAN>
I need help with closing this variable “rstTakLists” without it affecting the rest of the VBA code from executing properly. I don’t know where to place "rstTakLists.Close" without it affecting the rest of the VBA code and thus resulting in another Error of some sort.</SPAN>
Here is my code:
****So I added the following code after the "Loop" and it got rid of Error 3705 which was making me feel good, but then I ran a different scenario in which the User clicks on the Label Button, then clicks on the OK Button, and then clicks on the Yes Button and.........I get Run Time Error 3704: OPERATION IS NOT ALLOWED WHEN THE OBJECT IS CLOSED....
.....Error 3704 points me to this part of the code:
Now I am really stuck and need some help from the forum because I don't where to go from here.
Thanks,
- BC
I’m getting Run Time Error 3705: OPERATION IS NOT ALLOWED WHEN THE OBJECT IS OPEN when I click on a Label Button with code behind it in a MS Access Form I have. I think I found the thing causing Error 3705 within the code below which I believe has to with this variable "rstTakLists" that I created.
</SPAN>
SIDE NOTE: When I click LABEL BUTTON this is what literally happens...
1st: A message window appears that I created and all the User has to do is click on the OK button to continue
2nd: Another message window appears that I created that asks the User a question and the User has the option to click on either the Yes Button or No Button to continue
So when I click the Label button, then the OK button, and then on the No Button I get a window with Run Time Error 3705 and it highlights this VBA code ".Source = strSQLStmt" in yellow thus indicating that this is where the error is occurring. I don’t think the problem is with this VBA code ".Source = strSQLStmt", I think I am getting the Error 3705 because I need to close object “rstTakLists”. </SPAN>
I need help with closing this variable “rstTakLists” without it affecting the rest of the VBA code from executing properly. I don’t know where to place "rstTakLists.Close" without it affecting the rest of the VBA code and thus resulting in another Error of some sort.</SPAN>
Here is my code:
Code:
Dim conn As ADODB.Connection
Dim rstTakLists As ADODB.Recordset
Set conn = CurrentProject.Connection
Set rstTakLists = New ADODB.Recordset
If (totalSavings < DeltaCost) Then
ContinueFlag = True
ProgramCount = 0
With rstTakLists
strSQLStmt = "SELECT tblTakList.TakListID As TakListID " & _
" FROM tblTakList" & _
" ORDER BY tblTakList.TakListID;"
.Source = strSQLStmt
.ActiveConnection = CurrentProject.Connection
.Open Options:=adCmdTxt
End With
If Not (rstTakLists.EOF) Then
rstTakLists.MoveFirst
Else
boolError = True
strErrorMsg = "Error Code 3: Populating Programs Array failed, empty Recordset."
intErrorCode = 3
GoTo Scenario_Error
End If
End If
rstTakLists.MoveFirst
Do While Not (rstTakLists.EOF)
ProgramCount = ProgramCount + 1
arrProgramCutPeople(rstTakLists!TakListID) = 0
arrProgramCutDollars(rstTakLists!TakListID) = 0
arrProgramCutPercentage(rstTakLists!TakListID) = 0
rstTakLists.MoveNext
Loop
****So I added the following code after the "Loop" and it got rid of Error 3705 which was making me feel good, but then I ran a different scenario in which the User clicks on the Label Button, then clicks on the OK Button, and then clicks on the Yes Button and.........I get Run Time Error 3704: OPERATION IS NOT ALLOWED WHEN THE OBJECT IS CLOSED....
Code:
rstTakLists.Close
Set rstTakLists = Nothing
Set rstTakLists = New ADODB.Recordset
.....Error 3704 points me to this part of the code:
Code:
rstTakLists.MoveFirst</SPAN>
Now I am really stuck and need some help from the forum because I don't where to go from here.
Thanks,
- BC