PDA

View Full Version : Solved: array help



abcd1234
08-14-2007, 01:06 AM
i have a form with text boxes that a user would have to enter information into. i thought of making this a multi-dimensional array but figured that it would be too complicated to search as i'm pretty new to vba and don't know how to do that much.so when the user enters certain information such a surname and first name i want them to be stored in seperate arrays but in the same position. so i guess what i'm asking is how to i combine all these different text boxes which i have different arrays for to store all the information for one person seperately but still together so if i search for it it will come up?

fionabolt
08-14-2007, 04:13 AM
It would be much better to use an array, and once you've got to grips with them you will find them invaluable....

First you would need to create the variable:

Option Explicit
Dim ClientName() as variant

Then in your code, you would need to allocate storage space for the array (I find it helps to think of a multi-dimensional array like rows and columns).
So for example, if you had 10 names, and you wanted to store just the surname and the first name then:

ReDim ClientName(10,2)

Then you could store the information from the textboxes into the array, so say your first text box was called "txtSurname1" and the next "txtFirstname1" then:

ClientName(1,1) = the value of txtSurname1
ClientName(1,2) = the value of txtFirstname1

and so on.....

abcd1234
08-14-2007, 10:16 PM
yeah that's what i'm doing now. sorry if i don't understand your message but how exactly then do i connect all those seperate arrays together?

fionabolt
08-15-2007, 12:15 AM
Now it's my turn not to understand. What do you mean by

connect all those seperate arrays together?
What is it you are trying to do with this information once you've stored it?

abcd1234
08-15-2007, 02:55 AM
:hi: hey! maybe i don't really know how to do this:dunno so ill tell you what i want to do. i have a form that a user has to fill in with things like their name, address etc. i want to store all of this information and i want the user to be able to search through this information and be able to open the txt file that it gets stored in (i dont know if there is a function for that though).:banghead: so thats pretty much what i want done with the data. does that make more sense and less confusion for both of us?

fionabolt
08-15-2007, 03:08 AM
So you will have 10 forms that 10 different users will have filled in? To help me understand what you are trying to achieve, why would you want user 1 to be able to see what the other 9 had filled in?

abcd1234
08-15-2007, 03:20 AM
well its just one form that a user enters information of a member and they enter the information in text boxes. then theres another command button that the user can click to search with and they type a certain name and their information would come up. the person using this would be the person who does the data entry for the members

fionabolt
08-15-2007, 03:58 AM
OK - so you want to be able to utilize the information time and time again? Where are you going to store that information?

abcd1234
08-15-2007, 04:23 PM
well im going to store the information in a text file and i want it to be able to be retrieved when someone searches for it or want to open the file.

mdmackillop
08-16-2007, 02:33 PM
Why not store the data in a Excel. It's more amenable to searching and returning data.

abcd1234
08-16-2007, 02:56 PM
yeah it would be great to be able to store the data in excel and do it that way but my specs say that i cannot do that so i have to figure out another way to do it

fumei
08-22-2007, 11:12 AM
my specs
Better specs...better code.

It would possibly help if you actually stated what those specs are.

Generically, malcolm is quite correct. This should be Excel. Or maybe even Access, since what you describe sounds like the use of a database.

However, try telling us exactly what you are going to do. You are confusing. You are writing to a text file? You are getting stuff from a text file. OK. What is the format of the text file? Is this text file open? Is it a different file from the Word document you are in? The same file? If it is the same file, then it is not a text file. Straight ASCII text files can not hold VBA code. In fact....what is in the Word document you have this code in?