473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Syntax help with Me.RecordSource and Cancel option validation

52
Hello,

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
  1. Private Sub Report_Open(Cancel As Integer)
  2. On Error GoTo Error_Handler
  3.  
  4. Me.Caption = "Select a Project"
  5.  
  6. DoCmd.OpenForm FormName:="Custom_Code_lookup", windowmode:=acDialog
  7.  
  8. 'Cancel the report if "Cancel" was selected on the form.
  9. If Forms!Custom_Code_lookup!txtContinue = "no" Then
  10.     Cancel = True
  11.     GoTo Exit_Procedure
  12. End If
  13.  
  14. Me.RecordSource = Forms!Custom_Code_lookup!txtWhereClause
  15.  
  16. Exit_Procedure:
  17.     Exit Sub
  18.  
  19. Error_Handler:
  20.  MsgBox "An error has occured: " & "Error Number " & Err.Number & ", " & Err.Description, Buttons:=vbCritical, Title:="Select a Project"
  21. Resume Exit_Procedure
  22. Resume
  23. End Sub
Mar 20 '07 #1
3 2248
MMcCarthy
14,534 Expert Mod 8TB
The problem is you open the form as a dialog so the following code doesn't get written until the form is closed at which time the controls txtContinue and txtWhereClause are no longer available. The only way around this is to declare two GLOBAL variables in a module to take the values of these textboxes. Pass the values in on the On Close event of the form and use the variables instead of the textboxes in the code.
Mar 21 '07 #2
Birky
52
Mary,

I am not closing the form, I am just hiding it once the selection has taken place.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2. On Error GoTo Err_Command2_Click
  3.  
  4. Me!txtContinue = "no"
  5. ' Me.Visible = False
  6.  
  7. Exit_Command2_Click:
  8.     Exit Sub
  9. Err_Command2_Click:
  10.     MsgBox Err.Number & ", " & Err.Description
  11.     Resume Exit_Command2_Click
  12.     Resume
  13. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command9_Click()
  2. On Error GoTo Err_Command9_Click
  3.  
  4. RebuildWhereClause
  5. Me!txtContinue = "yes"
  6. ' Me.Visible = False
  7.  
  8. Exit_Command9_Click:
  9.     Exit Sub
  10. Err_Command9_Click:
  11.     MsgBox Err.Number & ", " & Err.Description
  12.     Resume Exit_Command9_Click
  13. End Sub
Expand|Select|Wrap|Line Numbers
  1. Sub RebuildWhereClause()
  2. On Error GoTo Err_RebuildWhereClause
  3.  
  4. Dim varWhereClause As Variant
  5. Dim strWhereAnd As String
  6. Dim strSelectionTitle As String
  7. Dim strComma As String
  8.  
  9. varWhereClause = Null
  10. strWhereAnd = ""
  11. strSelectionTitle = ""
  12. strComma = ""
  13.  
  14. If Not (Me!Project_Name & "" = "") And Not (Me!Project_Name = 0) Then
  15.     varWhereClause = (varWhereClause + strWhereAnd) & " (Event_Log.Project_Name = """ & Me!Project_Name.Column(0) & """)"
  16.     strWhereAnd = " AND "
  17.     strSelectionTitle = strSelectionTitle & strComma & "Project_Name = " & Me!Project_Name.Column(0)
  18.     strComma = ", "
  19. End If
  20.  
  21. If strWhereAnd = "" Then
  22.     varWhereClause = Null
  23. Else
  24.     varWhereClause = " WHERE " + varWhereClause
  25. End If
  26.  
  27. Me![txtWhereClause] = varWhereClause
  28. Me![txtSelectionTitle] = strSelectionTitle
  29.  
  30. Exit_RebuildWhereClause:
  31.     Exit Sub
  32. Err_RebuildWhereClause:
  33.     MsgBox Err.Number & " , " & Err.Description
  34.     Resume Exit_RebuildWhereClause
  35.     Resume
  36. End Sub
Are the values not accessible when the object is hidden and not closed? Do I still have to declare the global variables or am I using the wrong syntax in my code?
Mar 21 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
A dialog form remains in focus until close. Remove the dialog bit and see if you still have a problem.

Mary
Mar 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ColinWard | last post by:
Hi. I have a form which has as its recordsource an SQL string. The SQL String is as follows: SELECT * from CONTACTS where false. this ensures that there is no data loaded in the form when the...
3
by: MB | last post by:
Hi, I am doing a project which uses asp.net to develop its forms. The form uses validation web controls to validate the data entered in text boxes. When Cancel Button is pressed which is to exit...
6
by: Peter M. | last post by:
Hi all, If an event has multiple subscribers, is it possible to cancel the invocation of event handlers from an event handler? Or to be more specific: I'm subscribing to the ColumnChanging...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
1
by: ricky.fung | last post by:
I have several VBA functions in my Access Database that do not work. I have a combobox that filters my subform data however I cannot select anything when logged in with Read Only permission. ...
1
by: Giordano | last post by:
I am trying to construct a report menu that will allow the user to select any combination of 3 variables from 3 combo boxes (Select Subject/SelectCategory/Date Range). There are 2 possible options...
3
by: snoonan | last post by:
The company in quesiton does construction work. Tables look like this: ***Job Table*** JobNumberID* JobName ***JobNote Table*** JobNoteID* JobNumberID* JobNoteCreateDate
1
by: Webstorm | last post by:
Hi, I hope someone can help me sort this out a bit, Im completely lost. Here is the page I am working on: http://www.knzbusinessbrokers.com/default.asp I have 3 search critera that I need to...
6
by: Jim Wooseman | last post by:
I'm trying to use Greasemonkey to add form validation to some Web pages (whose construction is otherwise out of my control). To boil it down to a simple test case, the combination of the original...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.