Solved

Hash equivalent in Access

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

760 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

19 Experts available now in Live!

Get 1:1 Help Now