473,587 Members | 2,509 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting exception in method GetCustomProp(p rpName As String)

3 New Member
Hello all,

I am new to MS Access VBA, i am using 2007 version.

I have a form called feedback, in that load event we calling a method, in that method statement a bug is coming.

here is the method code
Expand|Select|Wrap|Line Numbers
  1. Function GetCustomProp(prpName As String) As Variant
  2.     On Error Resume Next
  3.     GetCustomProp = CurrentDb.Containers("Databases").Documents("UserDefined").Properties(prpName).Value
  4.     If Err.Number <> 0 Then GetCustomProp = Null
  5. End Function
This method is called in the form_load method
Expand|Select|Wrap|Line Numbers
  1. UpdateRating GetCustomProp("Rating")
In this method, GetCustomProp having a empty value, because of that is giving error.

Can any one explain me this statement
Expand|Select|Wrap|Line Numbers
  1. GetCustomProp = CurrentDb.Containers("Databases").Documents("UserDefined").Properties(prpName).Value
what actually is this code. I am working on a project which is build by some one else. actually i dont know what actually is this line of code is doing.

I had attached the whole page code with this issue. please have a look at this attachment.

Thanks in advance!
Asif
Attached Files
File Type: txt feeback form code.txt (1.3 KB, 441 views)
Nov 18 '09 #1
9 2328
ADezii
8,834 Recognized Expert Expert
GetCustomProp() is a Function that retrieves the Value of the User Defined Database Property passed to it. A User Defined Property doesn't exist until you request Access to create it, or you create it. The syntax for referring to these Properties is: Properties("<Na me>"). The code for retrieving all User Defined Properties for the Current Database is:
Expand|Select|Wrap|Line Numbers
  1. Dim intCounter As Integer
  2. Dim intPropNum As Integer
  3.  
  4. intPropNum = CurrentDb.Containers("Databases").Documents("UserDefined").Properties.Count
  5.  
  6. For intCounter = 0 To intPropNum - 1
  7.   Debug.Print "Property Name: " & _
  8.                CurrentDb.Containers("Databases").Documents("UserDefined").Properties(intCounter).Name & _
  9.                " | Property Value: " & CurrentDb.Containers("Databases").Documents("UserDefined").Properties(intCounter).Value
  10. Next
You can manually or programmaticall y Add a Database User Defined Property. I manually added a 'Rating' User Defined Property with a Value of Excellent in the following manner:
  • File
  • Database Properties
  • Custom Tab
  • Typed Rating in the Name Text Box
  • Kept the Type as Text
  • Set the Value as Excellent
  • OK
  • I then ran the above listed code to obtain the following results which will be different from your Database:
    Expand|Select|Wrap|Line Numbers
    1. Property Name: Name | Property Value: UserDefined
    2. Property Name: Owner | Property Value: admin
    3. Property Name: UserName | Property Value: admin
    4. Property Name: Permissions | Property Value: 0
    5. Property Name: AllPermissions | Property Value: 65536
    6. Property Name: Container | Property Value: Databases
    7. Property Name: DateCreated | Property Value: 11/18/2009 1:24:01 PM
    8. Property Name: LastUpdated | Property Value: 11/18/2009 1:24:01 PM
    9. Property Name: NWVersion | Property Value: 8.0
    10. Property Name: Rating | Property Value: Excellent
    11.  
Nov 18 '09 #2
asifu9
3 New Member
Hi ADezii,

thanks a lot for clarifying the code, but i am wondering where to create this database property varialble.
As i am using MS Access 2007, i have set of tables, it would be greate if u guide me how to create this variable.

Again, thanks a lot.
Asif
Nov 18 '09 #3
ChipR
1,287 Recognized Expert Top Contributor
It took a little digging, but I found this article on Microsoft Support which explains everything: Using DAO to Set and Retrieve Custom Database Properties
I have not yet determined the latest version to which it applies.
I suspect that the custom property you name does not exist, but you can determine that with this code modified from msdn.microsoft. com:
Expand|Select|Wrap|Line Numbers
  1. Sub UserProps()
  2.  
  3.    Dim db As Database
  4.    Dim prpLoop As Property
  5.  
  6.    Set db = CurrentDb
  7.  
  8.    With db.Containers!Databases.Documents("UserDefined")
  9.          Debug.Print "Properties of " & .Name & " document"
  10.          On Error Resume Next
  11.          For Each prpLoop In .Properties
  12.             Debug.Print "  " & prpLoop.Name & " = " & _
  13.                prpLoop
  14.          Next prpLoop
  15.          On Error GoTo 0
  16.    End With
  17.  
  18.    db.Close
  19.  
  20. End Sub
  21.  
Never mind, ADezii beat me to it.
Nov 18 '09 #4
ADezii
8,834 Recognized Expert Expert
@asifu9
ChipR provided a nice Reference for you to use - nice job ChipR! The only problem that I see is that the Linked Code does not check to see if the Property currently exists, which ChipR already addressed.
Nov 18 '09 #5
ChipR
1,287 Recognized Expert Top Contributor
A good solution would handle the possibility that the property does not exist by checking the return value of the function. Just from looking at the code, maybe something as simple as
Expand|Select|Wrap|Line Numbers
  1. UpdateRating Nz(GetCustomProp("Rating"), 0)
Nov 18 '09 #6
ADezii
8,834 Recognized Expert Expert
@ChipR
Just as a side-note, ChipR, traditional programming checks for an Error Code of 3270 (Property Not Found), then Dynamically creates it:
Expand|Select|Wrap|Line Numbers
  1. If Err.Number = 3270 Then       'Property not found
Nov 18 '09 #7
ChipR
1,287 Recognized Expert Top Contributor
Thanks Adezii. I know very little about the Err object.
Is it a global object that would be available to check in Form_Load after it returns from the GetCustomProp function, should this be checked inside the function, or is there a way to propogate it out of the function?

And, what is this "traditiona l programming" you speak of?
Nov 18 '09 #8
NeoPa
32,566 Recognized Expert Moderator MVP
@ChipR
The Err object is indeed global. It is always available, but as it is set (reset) after most operations, it is necessary to jump on it quickly if you want an accurate reflection of what it tells you. IE. It is easy to have code that resets it as a lead-up to displaying it for the operator. F1 on the word Err in the VBA editor window will give you a fuller description.
@ChipR
Just what one most frequently finds in example code from MS etc on the web.
Nov 18 '09 #9
ADezii
8,834 Recognized Expert Expert
@ChipR
The Function GetCustomProp() actually does this, but in a different manner:
  1. The Value of the User Defined Property is assigned to the Function.
  2. If the Property doesn't exist (hasn't been created), Error 3270 is generated.
  3. Because of the previously defined On Error Resume Next Statement, code execution continues to the next line.
  4. If any Error is generated (If Err.Number <> 0), the Function simply returns NULL without giving the User the chance to create the Property.
Expand|Select|Wrap|Line Numbers
  1. Function GetCustomProp(prpName As String) As Variant 
  2.     On Error Resume Next 
  3.     GetCustomProp = CurrentDb.Containers("Databases").Documents("UserDefined").Properties(prpName).Value 
  4.     If Err.Number <> 0 Then GetCustomProp = Null 
  5. End Function 
Nov 18 '09 #10

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

Similar topics

0
1024
by: Vikram | last post by:
I want comma seprated string of all the values in a particular column of a datatable. Is there any method available in datatable or any other easier way instaed of looping through the datatable. Thanks
3
1679
by: neoswf | last post by:
hi. i want to shorten getElementById() string at my files. ive writen this function: function gebi(el){ document.getElementById(el) } and when i try to call an ID, i try to call him like this: gebi('myID'). but this method doesnt succeed. can you please assist me to achive that goal?
1
1056
by: Michael Hesse | last post by:
Hi, I have a C++ DLL that I call from a VB.Net app. I need to call a function from VB in the DLL and get string data back. Any suggestions on how to do this? What kind of parameters do I use on each end? Thanks,
6
34904
by: Rico | last post by:
Hello, I'm looking for a way to reference the string name of an enumerator. I know in VB.net you can do "MyEnum.ToString" and get the name instead of the integer value. Is there a way I can do something similar with an Enum created in Access? Alright, here is some air code to explain what I mean Public Enum MyEnum
1
2199
by: MAF | last post by:
Is there a simple way to get the text, xml, from an xmlwriter. I have a XML writer that writes to a file, and I want another function to return the text that the xml writer is produced. Any suggestions?
2
6646
by: Hetal | last post by:
Hi... I am a newbie VB.NET developer and i am looking at working with ADO.NET rather than ADO. In one of our native VB application with ADO, we used to create 1 connection object and that would help us to connect to MS-SQL and MySQL alternatively based on the database type and connection string i provide. So, one connection object was good enough to connect to any of these 2 type of databases. The sample connection string we use to...
3
2660
by: =?Utf-8?B?c3BkMzAwMQ==?= | last post by:
I have a C++/CLI app that uses a logging control in an ATL COM Server. C++ Interop seems to work just fine to pass data from the C++/CLI app to the ATL Control but I can't seem to figure out how to get a string value back from the ATL Control. When debugging the code seen below, I see that the VARIANT pointed to by 'data' is updated but the String 'str' passed from the C++/CLI app doesn't change. So the String 'str' seems to be passed by...
0
1018
by: j.lendholt | last post by:
Hey Folks, it's some years ago i wrote applications in VB respectively VB .NET 2003. We have a java-application based on java-scokets. We try to connect to the server, send up a string, let the server-app work and wait for a server-response. The VB-App connects correctly to the java-app in port 11111 on our
1
1784
by: shivendra | last post by:
Hi, I have one Req where I have to get the portion of the string ,like I have one e-Mail iD "shivendra.narayan@rediffmail.com". I need only rediffmail.com now. Means to say get the string after the '@' PLZ help me Thank You, Shivendra
0
7923
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8221
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.