?
Solved

Hash equivalent in Access

Posted on 2008-11-02
5
Medium Priority
?
242 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 800 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

800 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