473,405 Members | 2,445 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,405 software developers and data experts.

Getting exception in method GetCustomProp(prpName As String)

3
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, 439 views)
Nov 18 '09 #1

✓ answered by ADezii

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("<Name>"). 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 programmatically 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.  

9 2319
ADezii
8,834 Expert 8TB
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("<Name>"). 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 programmatically 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
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 Expert 1GB
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 Expert 8TB
@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 Expert 1GB
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 Expert 8TB
@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 Expert 1GB
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 "traditional programming" you speak of?
Nov 18 '09 #8
NeoPa
32,556 Expert Mod 16PB
@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 Expert 8TB
@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
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. ...
3
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:...
1
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...
6
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...
1
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...
2
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...
3
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...
0
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...
1
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.