Archived

This topic is now archived and is closed to further replies.

Crispy

simple VB stuff

Recommended Posts

Hi, I''m greener than green in VB, and what''s more important, I don''t like it (VB, that is). However, I need to build a database in Access and I see no way around it. So here are a couple of things I''m not sure of. If it looks like I''m lacking some basic tut info here, I really don''t have the time to read tutorials anymore. By employer''s a jerk for stalling, and now I have to do the whole thing in less than 2 weeks... So here goes: I''m not 100% sure what a module is - is it the C equivalent of a file? In Access VB - if the functions are sorted in different windows according to the Forms they originate from, and are called MS Access Class Objects, does this still mean that each one is a separate module. How can I declare a variable that is "cross-object", so to speak. What I need to do is: 1) When the user presses a btn on a Form in Access, store a custom destination Field name in a global variable (tried Public, but it doesnt'' seem to be working) 2) Open a new form 3) When the user chooses sth in a list box in the new form, set the field stored in the global value to a some new value All in all - how do I create globals in VB? Everything else is luckily working. Thanks in advance, Crispy

Share this post


Link to post
Share on other sites
In VB you must declare the global variables with the "Global" keyword, not "Public" (I don''t know if the Global keyword applies to VBA however as I have no knowledge of it).
Hope this works!

Share this post


Link to post
Share on other sites
quote:
I'm not 100% sure what a module is - is it the C equivalent of a file?


In Access, modules are basically a file that you can store global functions in (and global variables).

quote:
In Access VB - if the functions are sorted in different windows according to the Forms they originate from, and are called MS Access Class Objects, does this still mean that each one is a separate module.


Yes all forms have their own module, usually refered to as object modules. If you want to use functions over multiple forms, put them into a regular module.

quote:
How can I declare a variable that is "cross-object", so to speak [...] All in all - how do I create globals in VB?


Use the 'Global' keyword rather than the 'Public' keyword. The variable will also have to be in a regular module and not a object module because the object module is only available when the form/report is open.

Hope this helps.
- Micah

-= Edit =-
formatting errors

[edited by - ISOPimp on July 15, 2002 5:29:03 PM]

Share this post


Link to post
Share on other sites
Thanks guys! - didn''t realise it had to be declared in a separate module.

Another problem came up though:

I store the "location" of the target control as a string (i e "Forms!MyForm!MyField") globally. Later on I need to access it as an object, though. Is it possible to "cast" (hehe) the string into the corresponding object, or do I have to create the variable As New Something? What should Something be in the case of an edit box?

Crispy

Share this post


Link to post
Share on other sites