473,322 Members | 1,241 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,322 software developers and data experts.

Errors with VBA Code in Class Objects in accde database

Hi, this is my first post here, so I hope I'm doing it right.

After converting an Access 2007 accdb database to accde, the vba code in my modules runs OK, but the code in my class objects (forms) wont run. In these cases, I always get the error message "The expression On Dbl Click you entered as the event property setting produced the following error: Can't perform operation since the project is protected" (or something similar depending on the particular event).

Please note that I don't get any errors when running the accdb file.

I don't understand why some of the code works, and some doesn't. I have searched Google for several days to find a solution, but I can't find this situation.

I am converting the front end file only to accde, not the back end tables. I do have a custom ribbon xml script in table UsysRibbons, which is located in the front end (because it doesn't work if I put it in the back end).

My files are all in trusted locations, I compile immediately before making the accde file, I've checked my References, I've de-compiled and compiled, I've copied all objects to a new (clean) database, I've even tried it with mdb and mde. Same problem every time.

My references are:
Visual Basic For Applications
Microsoft Access 12.0 Object Library
OLE Automation
Microsoft Office 12.0 Access database engine Object
Microsoft Office 12.0 Object Library
Microsoft Scripting Runtime

Any suggestions would be greatly appreciated.
Jul 12 '14 #1

✓ answered by Rabbit

Because once the code is compiled, there is no such concept as modules anymore. Modules are a way for humans to organize code, computer code needs no such paradigm.

There's no need to explicitly define the module in each sub. Define a constant at the module level and use that constant in all your subs.

12 2252
Rabbit
12,516 Expert Mod 8TB
You would need to post the expression that you entered on the double click to offer any help. Hard to tell you why the code won't work if you don't tell us what the code is.
Jul 12 '14 #2
Sorry about that. Here is the code.

Expand|Select|Wrap|Line Numbers
  1. Private Sub UserName_DblClick(Cancel As Integer)
  2.  
  3. 'On Error GoTo Err_Handler
  4. Dim strModName As String
  5. strModName = Me.Module.Name
  6.  
  7.     If (Form.Dirty) Then
  8.         DoCmd.RunCommand acCmdSaveRecord
  9.     End If
  10.  
  11.     'Opening Argument at end of following command is used to show/hide some buttons on details form
  12.     DoCmd.OpenForm "frm_UserDetails", acNormal, "", "[UserID]=" & UserID, , acDialog, "oaEdit"
  13.  
  14. Exit_Handler:
  15.      Exit Sub
  16. Err_Handler:
  17.       Select Case Err.Number
  18.       Case 9999                         
  19.           Resume Next                   
  20.       Case 999                          
  21.           Resume Exit_Handler           
  22.       Case Else 
  23.           Call LogError(Err.Number, Err.Description, strModName, "UserName_DblClick()")
  24.           Resume Exit_Handler
  25.       End Select
  26.  
  27. End Sub
  28.  
Jul 12 '14 #3
NeoPa
32,556 Expert Mod 16PB
I see nothing in that code that might lead to such an error message.

Perhaps you could narrow down the search by telling us which line number the error occurs on (if you have any way of knowing that).
Jul 12 '14 #4
After a lot of good old "trial and error", I've nailed the problem down to the error code (if I delete the error code lines, it works OK).

I will try to limit it down further, then post another message.

The thing that is really concerning me is: why does it work in accdb format, but not in accde format?
Jul 13 '14 #5
I've found the offending line of code:
Expand|Select|Wrap|Line Numbers
  1. strModName = Me.Module.Name
It seems that Me.Module.Name works fine in accdb, but not in accde format. I have no idea why it should be different (but it would be nice to find out).

I need to know the module name so that I can include it in my error table.

As a work-around, I can manually type in the module name for every sub, but if anyone knows another way to programmatically determine it, that would be great.
Jul 13 '14 #6
Rabbit
12,516 Expert Mod 8TB
Because once the code is compiled, there is no such concept as modules anymore. Modules are a way for humans to organize code, computer code needs no such paradigm.

There's no need to explicitly define the module in each sub. Define a constant at the module level and use that constant in all your subs.
Jul 13 '14 #7
Now it makes total sense regarding the modules.

I've defined a constant for each form and it works fine now (less lines of code than before).

Thanks very much for your quick advice.
Jul 13 '14 #8
Rabbit
12,516 Expert Mod 8TB
No problem, good luck with the rest of your project.
Jul 13 '14 #9
NeoPa
32,556 Expert Mod 16PB
Alternatively, as the default name for an associated class module is "Form_" or "Report_" followed by the actual name of the object, then the following code may work :
Expand|Select|Wrap|Line Numbers
  1. strModName = IIf(TypeOf Me Is Form, "Form_", "Report_")+Me.Name
Jul 13 '14 #10
MikeTheBike
639 Expert 512MB
Hi

I am a little confused here, wouldn't
Expand|Select|Wrap|Line Numbers
  1. strModName = Me.Name
work for the purpose of identifying the 'Module' (Form or Report) returning the error message?

I must be missing something!

MTB
Jul 14 '14 #11
Thanks NeoPa for your suggestion, but prefixing the form name with "Form" isn't necessary for me because I always start my form names with "frm".

Thanks MTB. KIS principal wins again :) I don't even recall how I ended up with Me.Module.Name originally (copy and paste I expect).

As you might have guessed, I am fairly new to VBA programming, so please excuse me if I ask dumb questions in the future :)
Jul 14 '14 #12
NeoPa
32,556 Expert Mod 16PB
That would certainly be fine for their needs MtB, but not a match for the question.

As it turns out the full module name isn't required after all, Me.Name is a fine and simple solution. It was only the OP's confusion that made the question different (and we like to answer the question where possible).
Jul 14 '14 #13

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

Similar topics

1
by: Johan | last post by:
Hi, The problem is : You have a class A with one or more data variables. You want to store the data variables in a database for example MySQL. Also you do not want to have SQL code in your...
7
by: Steven T. Hatton | last post by:
"Reduced subclassing. Factory Method (107) often produces a hierarchy of Creator classes that parallels the product class hierarchy. The Prototype pattern lets you clone a prototype instead of...
14
by: budy_ludy | last post by:
Hi All, I am new to vb .net, I have an ArrayList and i store class objects in it, and later i want to retrieve each ArrayList items and type cast to the class, How can it be done ? I used...
0
by: metaperl | last post by:
A Comparison of Python Class Objects and Init Files for Program Configuration ============================================================================= Terrence Brannon bauhaus@metaperl.com...
6
by: Tim Hunter | last post by:
I am using Access 2003 under WinXP. I currently support a huge Excel Wokbook that is a maintenance nightmare. There are about 15 worksheets each with lots of formulas...Anyway I am thinking of...
9
by: 7stud | last post by:
Hi, I'm trying to figure out what this passage from GvR's tutorial means: ------- Class definitions, like function definitions (def statements) must be executed before they have any effect.......
55
by: tonytech08 | last post by:
How valuable is it that class objects behave like built-in types? I appears that the whole "constructor doesn't return a value because they are called by the compiler" thing is to enable...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.