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 - Function GetCustomProp(prpName As String) As Variant
-
On Error Resume Next
-
GetCustomProp = CurrentDb.Containers("Databases").Documents("UserDefined").Properties(prpName).Value
-
If Err.Number <> 0 Then GetCustomProp = Null
-
End Function
This method is called in the form_load method - UpdateRating GetCustomProp("Rating")
In this method, GetCustomProp having a empty value, because of that is giving error.
Can any one explain me this statement - 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
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: - Dim intCounter As Integer
-
Dim intPropNum As Integer
-
-
intPropNum = CurrentDb.Containers("Databases").Documents("UserDefined").Properties.Count
-
-
For intCounter = 0 To intPropNum - 1
-
Debug.Print "Property Name: " & _
-
CurrentDb.Containers("Databases").Documents("UserDefined").Properties(intCounter).Name & _
-
" | Property Value: " & CurrentDb.Containers("Databases").Documents("UserDefined").Properties(intCounter).Value
-
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:
- Property Name: Name | Property Value: UserDefined
-
Property Name: Owner | Property Value: admin
-
Property Name: UserName | Property Value: admin
-
Property Name: Permissions | Property Value: 0
-
Property Name: AllPermissions | Property Value: 65536
-
Property Name: Container | Property Value: Databases
-
Property Name: DateCreated | Property Value: 11/18/2009 1:24:01 PM
-
Property Name: LastUpdated | Property Value: 11/18/2009 1:24:01 PM
-
Property Name: NWVersion | Property Value: 8.0
-
Property Name: Rating | Property Value: Excellent
-
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
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: - Sub UserProps()
-
-
Dim db As Database
-
Dim prpLoop As Property
-
-
Set db = CurrentDb
-
-
With db.Containers!Databases.Documents("UserDefined")
-
Debug.Print "Properties of " & .Name & " document"
-
On Error Resume Next
-
For Each prpLoop In .Properties
-
Debug.Print " " & prpLoop.Name & " = " & _
-
prpLoop
-
Next prpLoop
-
On Error GoTo 0
-
End With
-
-
db.Close
-
-
End Sub
-
Never mind, ADezii beat me to it.
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.
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 - UpdateRating Nz(GetCustomProp("Rating"), 0)
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: - If Err.Number = 3270 Then 'Property not found
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?
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.
ADezii 8,834
Recognized Expert Expert @ChipR
The Function GetCustomProp() actually does this, but in a different manner: - The Value of the User Defined Property is assigned to the Function.
- If the Property doesn't exist (hasn't been created), Error 3270 is generated.
- Because of the previously defined On Error Resume Next Statement, code execution continues to the next line.
- If any Error is generated (If Err.Number <> 0), the Function simply returns NULL without giving the User the chance to create the Property.
- Function GetCustomProp(prpName As String) As Variant
-
On Error Resume Next
-
GetCustomProp = CurrentDb.Containers("Databases").Documents("UserDefined").Properties(prpName).Value
-
If Err.Number <> 0 Then GetCustomProp = Null
-
End Function
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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?
|
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,
|
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
|
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?
| |
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...
|
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...
|
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
|
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
|
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...
|
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...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |