I have a form with a subreport in it that has been working for months now. This form is called "RAMandLRAM" and the report is called "rRAM10x10" (planning on renaming these) but we'll call the form "fRAM" and the report "rRAM" for simplicity. fRAM is going to be opened as a popup form by clicking a button on another form, called "fHighRisk" (fHighRisk is a subform to "fRiskAssessmentTest"). I recently went in to improve some of the code in fRAM, as I've gotten much better / more familiar with VBA since creating it. I made sure to test everything I improved / replaced / added before moving on to the next so I could isolate any issues that occurred. The last thing I did before I started receiving the error was add in a way to check how the form was opened using 'Screen.ActiveControl.Name' and change the Tab Order of fRAM based on that. After adding that code to fRAM, I opened it in form view to ensure there weren't any problems, and didn't receive any errors. Then I wen't to fHighRisk and added 2 buttons to open fRAM, the names of which are whats checked for when the form opens to change the Tab Order. Once I tested that these buttons work, the error started appearing.
"Error 2455: You entered an expression that has an invalid reference to the property Form/Report"
The error appears on some lines that mess with the recordsource of the subreport rRAM, but not all of them.
i.e.
Code:
Me.rRAM10x10.Report.RecordSource ="tRAM10x10"
Removing the code I created before this error started appearing does not fix the error. The code is as follows:
(NOTE that I wrote "fHighRisk" instead of the parent form -> subform path for testing purposes)
Code:
If CurrentProject.AllForms("fHighRisk").IsLoaded =TrueThen
If Screen.ActiveControl.Name ="btnRAMimpact"Then
Me.btnForFocus.TabIndex =0
ElseIf Screen.ActiveControl.Name ="btnRAMlhood"Then
Me.Tabordertest.TabIndex =0
EndIf
EndIf
I've done some research, and everything I've found on the error states that it derives from the parent form (in this case fRAM) having no records in its recordset. Maybe I'm wrong, but I do not believe this is the case. fRAM isn't a form based on a table / query / etc., it's just a means to hold controls. More on that later.
I've also done a bit of troubleshooting, and have found the following so far:
- The recordsources I set to rRAM are all fine. They haven't been changed, and the correct data is still there.
- If I comment out all the lines that give me this error and try to open fRAM, the form opens, but entire form is blank for some reason. All the controls (buttons / labels / etc) are gone, even though their visible properties are set to 'Yes'.
- Adding "Option Explicit" to the module doesn't provide any extra information. (After adding it, Access yelled at me for not declaring the variables in my 'For' loops, but after that it went back to the same error on the same lines)
The Open event of fRAM adds appropriate captions to controls on the forms and not much else. It also calls the public subs "Refresh" and "Activate", which is where I'm getting all of the errors. Commenting out these calls doesn't prevent the error. Note that the error appears on lines that change the recordsource of the report (see example above) within the subs "Refresh" and "Activate" (These lines of code only appear in these two subs). I can post more code within "Refresh" and "Activate" if requested, but they're both fairly long and inefficiently built, which is why I only posted whats giving the error. (inefficient as in long IF loops & Case statements instead of simpler, more effective methods since I was new to VBA when I made those sections)
Just in case I'm missing something, here is the code for fRAM's open event.
Code:
Private Sub Form_Open(Cancel As Integer)
Dim sID As Integer
If CurrentProject.AllForms("fRiskAssessmentTest").IsLoaded = True Then
sID = Forms!fRiskAssessmentTest!fHighRisk!ScenarioID.Value
ElseIf CurrentProject.AllForms("fHighRisk").IsLoaded = True Then
sID = Forms!fHighRisk!ScenarioID.Value
Else
sID = 1
End If
Me.lblScenarioID.Caption = "Scenario " & sID
If CurrentProject.AllForms("fHighRisk").IsLoaded = True Then
If Screen.ActiveControl.Name = "btnRAMimpact" Then
Me.btnForFocus.TabIndex = 0
ElseIf Screen.ActiveControl.Name = "btnRAMlhood" Then
Me.Tabordertest.TabIndex = 0
End If
End If
clr1 = RGB(122, 197, 205)
clr2 = RGB(152, 245, 255)
'Call Refresh_Click
'Tells activate to not prompt for RAMsize when the form opens
RSmsg = "no"
'Call Activate_Click
'button colors
Dim lblName As String, btnName As String, ctrlName As String, lblCaption As String, Rating As Integer, ctrl As Control
For Each ctrl In Me.Controls
If ctrl.ControlType = acCommandButton Then
ctrlName = ctrl.Name
Me.Controls(ctrlName).BackColor = clr2
End If
Next
Dim i As Integer
'Darkens buttons if value is stored in table
For i = 1 To 5
lblName = "Vardisp" & i
lblCaption = Me.Controls(lblName).Caption
If IsNull(DLookup("[Variable Impact]", "tImpact", "scenarioID = " & sID & " AND [Impact Variable] = """ & lblCaption & """ ")) Then
GoTo Skip_loop2
Else
Rating = DLookup("[Variable Impact]", "tImpact", "scenarioID = " & sID & " AND [Impact Variable] = """ & lblCaption & """ ")
End If
Dim b As Integer
For b = 1 To 10
If Rating = b Then
btnName = "Var" & i & "R" & b
Me.Controls(btnName).BackColor = clr1
End If
Next
Skip_loop2:
Next
End Sub
Some context about fRAM and it's report:
(PLEASE NOTE: This was built a while ago and is in need of improvements)
The purpose of fRAM is to display a matrix for Risk Assessment. rRAM acts as the matrix; The user inputs the dimensions, and the matrix changes size (anywhere from 10x10 to 3x3) by changing it's recordsource to a table that has been laid out for those specific dimensions. fRAM is where user interaction happens; Buttons will appear / hide based on the dimensions of the matrix and a few other user dependent things, labels and captions change, so on and so forth. This form doesn't display any records from a table, it just acts as a means to display / interact with the risk matrix and perform calculations based on choices in the background. Hopefully that helps.
I'm pretty lost here, can't seem to find any kind of solution. Any help is greatly appreciated. Please let me know if I forgot to add something important here. Thanks!