Solved

Hash equivalent in Access

Posted on 2008-11-02
5
235 Views
Last Modified: 2013-11-27
I want to store some configuration parameters into a table in Access... load them up as Globals and use them the way one uses hashes in Perl.

The table would have two fields
param, val

Eg values would be
root_dir => "C:\test"
sender => "rajesh@hotmail.com"

I should be able to say
config('root_dir) and get "C:\Test" as my return value.

Regards,
Rajesh
0
Comment
Question by:kavirajesh
  • 2
5 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 200 total points
ID: 22865742
Access has no concept of "config" ...

You can use DLookup to get values from your table:

Dim sSender As String

sSender = DLookup("val","YourTableName","para='sender'")

0
 

Author Comment

by:kavirajesh
ID: 22865884
Every hit to DLookUp would touch the database right?

I wanted to avoid that...

Regards,
Rajesh
0
 
LVL 84
ID: 22865916
Yes ... you could also use an array of UserDefinedFunctions. Build the array when you make the connection to the database, then build a small helper function to get the values from it:

In the General Declarations of a Standard Module:

Public Type udtMyConfig
  Param As String
  Val As STring
End Type

Public MyArray() As udtConfig

In the code section of that module:

Function Build Array() As boolean

Dim bDimmed As Boolean

Redim MyArray(10)

MyArray(0).Param = "email"
MyArray(0).Val = "someone@someone.com"

MyArray(1).Param="smtp"
MyArray(1).Val = "smtp.someserver.com"

etc etc
End Function

Function GetValue(Param As String) As STring
  Dim i As Integer
  For i = 0 To Ubound(MyArray)
    If MyArray(i).Param = Param Then GetValue = MyArray(i).Val      
  Next i
End Function

Now just call GetValue("email") ... the function should return "someone@someone.com"
0
 
LVL 1

Expert Comment

by:mcai4mr2
ID: 23530475
you can use a Collection object. Collections can have Strings as a key. ie would be something like

    Dim config As Collection
    Set config = New Collection
   
    Call config.Add("C:\test", "root_dir")
    Call config.Add("rajesh@hotmail.com", "sender")

retrieval via:

config("root_dir")
config("sender")

gives you the results you would expect, "c:\test" and "rajesh@hotmail.com" respectively

hope this helps
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now