I’m hoping you can help me out with two issues I’m having with my code. I have an Access Report named Report_Project_Event_Log which I have calling a Form named “Custom_Code_lookup” which allows a user to select data for the report. I have a hidden txt object within this form named txtContinue which is either set to “no” or “yes”. I believe I have everything running correctly except for my cancel code below. When the Cancel button is select I have confirmed that the txtContinue object is getting updated with a “no” but the below code is errorring out telling me that the application can not find the form “Custom_Code_lookup”. I’m sure it has to do with my syntax and I’m hoping you can see what I’m doing wrong?
I am also having an issue setting the where clause to the reports RecordSource. Again I have a hidden txt object within the form named txtWhereClause which is where my code is building the WHERE itself. Again the object is getting populated appropriately within I just need to have it placed in the reports RecordSource. I am attempting to use the “Me.RecordSource = Forms!Custom_Code_lookup!txtWhereClause” code but it is not working. Again I believe this to be syntax for everything else is working fine.
Can you help me identify where I am going wrong on these two lines of code? Any help would be greatly appreciated.
Thanks
Birky
Expand|Select|Wrap|Line Numbers
- Private Sub Report_Open(Cancel As Integer)
- On Error GoTo Error_Handler
- Me.Caption = "Select a Project"
- DoCmd.OpenForm FormName:="Custom_Code_lookup", windowmode:=acDialog
- 'Cancel the report if "Cancel" was selected on the form.
- If Forms!Custom_Code_lookup!txtContinue = "no" Then
- Cancel = True
- GoTo Exit_Procedure
- End If
- Me.RecordSource = Forms!Custom_Code_lookup!txtWhereClause
- Exit_Procedure:
- Exit Sub
- Error_Handler:
- MsgBox "An error has occured: " & "Error Number " & Err.Number & ", " & Err.Description, Buttons:=vbCritical, Title:="Select a Project"
- Resume Exit_Procedure
- Resume
- End Sub