Passing variable to another form

veracity777

New member
Local time
Today, 19:53
Joined
Jul 10, 2003
Messages
8
Hi All,
I am new to MS Access, so although I am comfortable with programming concepts, I do not know how to make the contents of a public variable in one form available for use in another form.

The environments I am used to allow me to set a public variable, fill it with some data and then access that from almost anywhere in the application.

Do I need to specifically pass the parameter to the next form? If so, how?

cheers
 
Hi there,

You declare your public variables in a seperate module. At the database window, select the modules tab and click 'New' to take you to the VB environment. Declare your public variables in here then you can pass values to them from your sub-procedures in your forms.

Does that answer your question?

Rob
 
Passing variable to another form...

Hi Rob,

Thanks for the prompt reply.

Yes, that was what I was looking for. I had my public variable declared in the wrong place.

On another topic...
I have a need to data-drive the captions on some command buttons. What I want to do is search through a table for a row matching the button name and change the caption to the contents of another field in the same row.

Is this something you can help me with?

cheers
 
Data-driven buttons

Rob,
Sure, here goes...

I have a form that has a few rows of buttons on it. I want the caption of each button to display the contents of a field in a table.

So, for example, 4 buttons in each of two rows, eight buttons in all. The table contains eight records (eg: Short Black, Long Black, Latte, Afogatto, Expresso, Vienna, etc).

I would like these words to be read from the table at runtime and placed on the buttons base on the button name (which is also contained in a field in the same table).

I hope this makes sense:->)

cheers
 
Ok I think I understand :)

Am I correct in saying that this table is only a lookup table where you want to store your captions? Thus allowing you to change them in the table and then at runtime to set captions on all your forms by code without having to change them in design view?

Probably the best way do it is write a public sub to return the captions to some string variables and then in your form's On_Load event call the sub and set the caption of each of your buttons to the relevant string variable.

Is that what you want?
 
Hi Rob,

OK, what you say is making some sense.
Two things though.

Firstly, how/where do I put the public sub?

2ndly, The table I am pulling these button labels from also contains the value that will be added to the transaction total. So when I press button ColdDrink1 with the label "Coke", it will return to me the value $2.50

cheers
 
Hi there,

I've been thinking about this and I'm struggling to understand why it is you want to set your labels/captions for your buttons at run-time. Is it not practical for these to be set in design?

What I have done is attached an example (in Access 2000 format) of how to retrieve the prices based on the button clicked. This may or may not be what your looking for but I hope it will give you a few ideas :D

HTH
Rob
 

Attachments

Rob,

Thank you very much for the xample mdb file. I was completely unaware of the DLookUp function. it is exactly what I need.

To answer your question about the need to data-drive button labels at runtime...

The client is an organisation with a large crew of volunteer labour that are split into groups. Each group works at a cafe owned by the organisation on a rostered basis. The majority of the staffing at the cafe is by these volunteer groups, and this means that adherance to procedures is often not up to scratch. They want a way to identify those individuals that need more training, or who can explain anomalies in daily transactions.

So, I want to display each person's name on a login button that records their Employee ID. The label on the button will change depending on which group is rostered on for the month.

The second set of buttons to have label changes are the PLU buttons on the cash register form. This form is also data-driven, providing a very easy way to ensure that all transactions are accurate. Staff do not have to remember the latest specials as prices are driven from the table. When "theme" nights are conducted, and the menu changes completely for just one night, it is easy to "program" this cash register form by simply selecting a different menu table.

I do this type of thing all the time but never in Access, so I have been lost to understand both the paradigm and the syntax for a project with a very short timeframe.

cheers
 
Rob,

Thank you very much for the xample mdb file. I was completely unaware of the DLookUp function. it is exactly what I need.

To answer your question about the need to data-drive button labels at runtime...

The client is an organisation with a large crew of volunteer labour that are split into groups. Each group works at a cafe owned by the organisation on a rostered basis. The majority of the staffing at the cafe is by these volunteer groups, and this means that adherance to procedures is often not up to scratch. They want a way to identify those individuals that need more training, or who can explain anomalies in daily transactions.

So, I want to display each person's name on a login button that records their Employee ID. The label on the button will change depending on which group is rostered on for the month.

The second set of buttons to have label changes are the PLU buttons on the cash register form. This form is also data-driven, providing a very easy way to ensure that all transactions are accurate. Staff do not have to remember the latest specials as prices are driven from the table. When "theme" nights are conducted, and the menu changes completely for just one night, it is easy to "program" this cash register form by simply selecting a different menu table.

I do this type of thing all the time but never in Access, so I have been lost to understand both the paradigm and the syntax for a project with a very short timeframe.

cheers
 

Users who are viewing this thread

Back
Top Bottom