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.
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
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.
Sorry about that. Here is the code. -
Private Sub UserName_DblClick(Cancel As Integer)
-
-
'On Error GoTo Err_Handler
-
Dim strModName As String
-
strModName = Me.Module.Name
-
-
If (Form.Dirty) Then
-
DoCmd.RunCommand acCmdSaveRecord
-
End If
-
-
'Opening Argument at end of following command is used to show/hide some buttons on details form
-
DoCmd.OpenForm "frm_UserDetails", acNormal, "", "[UserID]=" & UserID, , acDialog, "oaEdit"
-
-
Exit_Handler:
-
Exit Sub
-
Err_Handler:
-
Select Case Err.Number
-
Case 9999
-
Resume Next
-
Case 999
-
Resume Exit_Handler
-
Case Else
-
Call LogError(Err.Number, Err.Description, strModName, "UserName_DblClick()")
-
Resume Exit_Handler
-
End Select
-
-
End Sub
-
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).
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?
I've found the offending line of code: - 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.
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.
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.
No problem, good luck with the rest of your project.
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 : - strModName = IIf(TypeOf Me Is Form, "Form_", "Report_")+Me.Name
Hi
I am a little confused here, wouldn't
work for the purpose of identifying the 'Module' (Form or Report) returning the error message?
I must be missing something!
MTB
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 :)
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).
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
by: metaperl |
last post by:
A Comparison of Python Class Objects and Init Files for Program
Configuration
=============================================================================
Terrence Brannon
bauhaus@metaperl.com...
|
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...
|
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.......
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
|
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...
| |