Accessing a table in VB

Shyama83

New member
Local time
Today, 12:16
Joined
Sep 3, 2008
Messages
9
Hi...
How can I access a table's information in VB?
I am currently working on a simple accounting application using Access.
What I'm trying to do now is adjust the number format of a textbox depending on the currency selection of the user. I created a currency-list table that stores the currencies with their appropriate decimal places (2 or 3). On a certain form, the user will have to select a currency and an amount to post entries. The currency list will be in a combobox, having its source be the currency-list table. Thus, when a selection is made in the combobox, i want to invoke an afterupdate event that will lookup the currency-list table, fetch the decimal places of the currency, then format the amount textbox accordingly..

How can I do that? I am not bad with programming.. but its been a while since I programmed so I don't know the syntax that ill have to follow in Access VB..

Please help... thaaanks a lot in advance!
 
i wouldnt worry about the table per se.

just store the data in there as double or currency - this will give you adequate precision.

When you display the data in forms/reports etc, then you might need to address the format issue, and then you would be able to iterate all the controls on a form, with something like this - these references arent correct, but you should get the idea

for each ctrl in me.controls
if ctrl.type = currency
then select case
case pound,dollar,euro : decimals = 2
case somethingelse: decimals =3
end select
next
 
Thanks.. that will work ;)
But what if I needed to access a database in VB? Because I think I want to do that in other parts of my code... how do I do that?
 
Are you using Visual Basic as your development tool or Ms Access?
 
you can access a table with this syntax (or a variation of this)

currentdb.tabledefs("tablename").propertyname

intellisense will offer you all the propertyname options

some have suboptions

eg the individuals fields in a table are

currentdb.tabledefs("tablename").fields("fieldname")

you can do things like

dim fld as field
for each fld in currentdb.tabledefs("tablename").fields
msgbox(fld.name & " " & fld.type)
next
 
Last edited:
Thank you thank you thank you !!!
I've been struggling with this this for quite some time now!! this will help me LOADS..

Thanks a million :)
 
if you get a problem with using currentdb directly - sometimes it falls out of scope for no apparent reason, just change the code to the following to cure this problem

dim dbs as database
dim fld as field

set dbs= currentdb
for each fld in dbs.tabledefs("tablename").fields
msgbox(fld.name & " " & fld.type)
next
 

Users who are viewing this thread

Back
Top Bottom