Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Magic Button 1

Status
Not open for further replies.

TadyB

Programmer
May 21, 2004
42
0
0
US
Hi again!
I know I'm new to this message board and I hope I'm not aggrevating everyone with posting so much. It's just such a great source to find out things I haven't been able to find in my Access Bible or the Access help. :)

Anywho...
I have about 40 different food items for sale in this program. They are divided into 4 tables. On my main screen I will have each item listed with a button next to it that, when pressed, will increase that item's quantity by 1. I know how to do this using a macro assigned to each button, but I was wondering if there is a faster, more efficient way of doing this. I will have to create 40 macros and 40 buttons. I'm wondering if this will slow the program down too much.

Is there a better way?

Thanks,
Stacey
 
Stacey, Please furhter explain the following:

What is the recordsource for the form where this button exists? Is it a query which contains all 4 tables?

Does the user see the quantity amount on the form? Is there a text box or something next to each button which contains the corresponding number? Or are there just buttons?



--
Mike

Why make it simple and efficient when it can be complex and wonderful?
 
Hey, thanks for the response...I don't explain things too well...sorry.

On my main form, I have 4 subforms for the 4 different tables.

The user does see the quantity. The fields in the tables are for these quantities. I'm using that data for inventory purposes also.

I'm not sure if that explains it well enough. I'm trying!!


Thanks,
Stacey
 
Thanks Stacey. Could you shed some more light on how exactly the user sees the quantity on the form? You've mentioned that these quantities are located in the table, but how does the user see them when they are working with the form? For example - The quantity amount is listed in a textbox next to the button.

--
Mike

Why make it simple and efficient when it can be complex and wonderful?
 
Yes, the quantity field is listed in a textbox next to the button. Sorry, I fogot that when you drag a field on a form it is called a text box.


Stacey
 
TadyB - Since you're working with Mike555 on this problem, I won't interrupt.

But I would like to take the chance to Welcome you to Tek-Tips, and I invite you to read FAQ222-2244 on how make the most out of your Tek-Tips experience.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
TadyB, I'm still looking into this for you. If anyone else knows how to do this in the mean time, please feel free to chime in. Thanks.

--
Mike

Why make it simple and efficient when it can be complex and wonderful?
 
TadyB, I've been trying to figure out how to do this the past few days but I'm stumped! I ended up cusing the test database I had setup to work on this problem, but to give you some direction (or anyone else who may read this thread) on my logic, here's what I was trying to do:

[ol]
[li]I was thinking you could assign the food name to each combo box and text box control. That name would be preceeded by either a cmd or txt. (Such as cmdApplePie & txtAppliePie for your hypothetical Applie Pie command button and corrosponding Apple Pie textbox).[/li]

[li]Upon setting up those names you could write a routine that would be called on the Open event of each command button. That routine would identify the name of the command button control (the current control) and then select a corresponding textbox where the FoodName matches. Basically it should shave off the initial cmd or txt and then search for the remaining string.[/li]

[li]Upon selection of the appropriate textbox, syntax to perform the calculation would look something like:
Me.txtAppliePie = Me.txtApplePie + 1
This syntax will obviously change because it would probably be using variables established in step 2 to identify the textbox name.[/li]
[/ol]

I appologize for not being able to completely answer your initial question, but hopefully there is an alternative method you find to perform this task, or the logic I've listed above will help someone (who's better at VBA than me) to answer your question.

--
Mike

Why make it simple and efficient when it can be complex and wonderful?
 
Mike,
I really truely appreciate your efforts. I'm reading over what you suggested, and at least I have somewhere to start! Gotta let my brain digest it for a while.

Again, Thanks...You have been so kind.

Stacey
 
Me.txtAppliePie = Me.txtApplePie + 1
This syntax will obviously change because it would probably be using variables

Something like this:
Me.Controls(theVariable) = Me.Controls(theVariable) + 1

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
How are ya TadyB . . . . .

If your subforms are continuous forms, [blue]you'll only need one button on each subform[/blue] in the detail section.

Also, have you given thought to a user incrementing 1 too many times (maybe they have clickitus or something)? . . . . Well . . . . I have!

Using a [purple]Spin Button[/purple] which allows incrementing and decrementing, I can work up the code for ya. Just need the following info:

Are the subforms infact continuous forms?

What are the [blue]subform Names[/blue] and associated [purple]Quantity[/purple] [blue]TextBox Name[/blue]?

cal.gif
See Ya! . . . . . .
 

Thanks [blue]PHV[/blue], That info put me back on track!

[blue]TadyB[/blue], You can do the following to perform this function:
[ol]
[li]Assign the name of the food to the command button name. Do not preceed the name with cmd as previously mentioned. [highlight]i.e...Name the command button for AppliePie AppliePie[/highlight][/li]

[li]Assign that same food name to the corresponding textbox but preceed the name with txt. [highlight]i.e...Name the textbox for AppliePie txtAppliePie[/highlight][/li]

[li]At the very top of the form's VBA you should have:
Code:
Option Compare Database
Option Explicit
Dim CmdCtrlName As String
Dim TxtCtrlName As String
[/li]

[li]Then create an On Click event for each button with the following code:
Code:
CmdCtrlName = Screen.ActiveControl.Name
TxtCtrlName = "txt" & CmdCtrlName

If IsNull(Me.Controls(TxtCtrlName)) Then Me.Controls(TxtCtrlName) = 0 [COLOR=green]'For use if null values exist[/color]
Me.Controls(TxtCtrlName) = Me.Controls(TxtCtrlName) + 1
[/li]
[/ol]

You will need to create a Click event for each command button.

HTH

--
Mike

Why make it simple and efficient when it can be complex and wonderful?
 
Thanks y'all! I'm working on it...I appreaciate everything you've done!! What would I do without you????


Stacey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top