Solved

Hash equivalent in Access

Posted on 2008-11-02
5
233 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

863 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

22 Experts available now in Live!

Get 1:1 Help Now