dbTalk Databases Forums  

global arrays in a module

comp.databases.ms-access comp.databases.ms-access


Discuss global arrays in a module in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
eaglewingmd
 
Posts: n/a

Default global arrays in a module - 09-15-2010 , 09:44 AM






I'm using Access 2007.
I probably need a tutorial because I have tried to piece this together
from different sources. I am sure this is a simple thing but I can't
wrap my mind around it.

I have a table with item names in it. These are the labels for the
values I have in a second table.
I need to create a module which will be called in the main/first form
to load an array with the label names.
Then I need to use that array throughout the project, on forms and
reports.
I would like to have it display on the forms and reports
'dynamically', with a for loop so that I do not have to hard code the
form. Letting the number of items determine what is displayed. This
problem is not my main concern, I can always work around it.

My main concern/problem is the module and global array variables. I
can't make it work. The rest I can probably work my way through.

The code I have so far doesn't work at all.
I need to decalre the arry, find out the number of labels in the file,
redim the array for that number then open the table and fill the
array.
I think I know what to do I just don't know how to do it.

Thanks for your help.

Reply With Quote
  #2  
Old   
Rich P
 
Posts: n/a

Default Re: global arrays in a module - 09-15-2010 , 10:04 AM






Quote:
I have a table
The table IS your global array. Use the table values.

Rich

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
  #3  
Old   
Salad
 
Posts: n/a

Default Re: global arrays in a module - 09-15-2010 , 12:19 PM



eaglewingmd wrote:

Quote:
I'm using Access 2007.
I probably need a tutorial because I have tried to piece this together
from different sources. I am sure this is a simple thing but I can't
wrap my mind around it.

I have a table with item names in it. These are the labels for the
values I have in a second table.
I need to create a module which will be called in the main/first form
to load an array with the label names.
Then I need to use that array throughout the project, on forms and
reports.
I would like to have it display on the forms and reports
'dynamically', with a for loop so that I do not have to hard code the
form. Letting the number of items determine what is displayed. This
problem is not my main concern, I can always work around it.

My main concern/problem is the module and global array variables. I
can't make it work. The rest I can probably work my way through.

The code I have so far doesn't work at all.
I need to decalre the arry, find out the number of labels in the file,
redim the array for that number then open the table and fill the
array.
I think I know what to do I just don't know how to do it.

Thanks for your help.

Rich pointed out the tables work. This sub will list the field names
Sub FldNames()
'list field names of a table
Dim tdf As TableDef
Dim fld As Field
Dim dbs As Database
Set dbs = CurrentDb
Set tdf = dbs.TableDefs("CallingCard")
For Each fld In tdf.Fields
MsgBox fld.Name
Next
Set tdf = Nothing
End Sub

For a global array, here's an option
In a module, create a TYPE array
Type RecLayout
Field1Name As String
Field2Name As String
End Type

In a form's module you could have as the top 3 lines. This creates a 1
element array.
Option Compare Database
Option Explicit
Dim RL(0) As RecLayout

Then somewhere in your code
RL(0).Field1Name = "One"
RL(0).Field2Name = "Two"
msgbox RL(0).Field1Name
msgbox RL(0).Field2Name

Here's one that can change size of the Type array.
Static ar() As RecLayOut
Static Entries As Integer
Dim Entries As Integer
Entries = 0
For Entries = 0 to numRows -1
ReDim Preserve ar(Entries)
Next

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.