Solved

Hash equivalent in Access

Posted on 2008-11-02
5
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 85

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 85
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

691 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