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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need sone help on how to assign prices to combo box list 1

Status
Not open for further replies.

miscluce

MIS
Oct 4, 2007
149
US
Hello,

Its been awhile since I have done something like this. I need a little help from the experts. I am doing an exercise that will calculate the bill for a doughnut shop and eventually I am going to use relational tables wants the program gets big enough. BUt first, I like to keep it simple and fun.

I have a form with two cboboxes(cbodoughnuts, cboBeverages) I have two tables (tblDoughnuts, tblBeverages)
tblDOughnuts has two fields(fldDoughnuts, fldPrice)
tblBeverages has two fields(fldBeverages, fldPrice)

Each of the cboboxes are populated with the correct listed items such as glaze, powder, juice, and coffee.

My question is how can I assign a price for each of the items so that when the user makes the selections in the cboboxes a price will get totaled when I hit a button.

thanks in advance.
 
A few ways to do it. I guess the easiest is to set the bound column of the cboDoughnuts and cboBeverages to their prices, then in the onclick event of the cmdButton you have do the calculation.

Code:
sub cmdTotal_Click()
  cboBeverages + cboDoughnuts = curTotal
  msgbox "Your total is: " & curTotal
end sub

All lessons learned from the School of Hard Knocks........at least tuition is cheap.
 
why does my plus sign disappear when I type it? Also, I get a compile error: invalid use of property.

Dim curTotal As Integer
Me.cboBeverages Me.cboDoughnuts = curTotal
MsgBox "Your total is: " & curTotal
 
The calculation is backwards

[red] cboBeverages + cboDoughnuts = curTotal[/red]
should be:
[green] Me.txtCurTotal = Me.cboBeverages.Column(1) + cboDoughnuts.Column(1)[/green]

The column number counts from 0.

This may be fun but it isn't best practice for creating a relational database...



Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
I got it to run at least but its adding the doughnut plus coffee instead of the prices($2+$3)??

As a result, I have a compile error with a datatype mismatch.

here is what I have

Private Sub Command11_Click()

Dim curTotal As Integer
curTotal = Me.cboBeverages + Me.cboDoughnuts
MsgBox "Your total is: " & curTotal
End Sub

and bound colunm = 2 which is the price colunm
 
disregard last post I got it now. thanks.

"This may be fun but it isn't best practice for creating a relational database..."

well, what would you consider best practice for realtional database? eventually I will have to create an invoice program that prints invoices according to selections from multiple combo boxes that are cascaded from one another.

I know I need to use a relational database for this which is seperate from the actual coding but its the coding I need to practice more on.
 
Apparently your values aren't bound to a numeric field. Try
Code:
Private Sub Command11_Click()
 
 Dim curTotal As Integer
 curTotal = Val(Me.cboBeverages) + Val(Me.cboDoughnuts)
  MsgBox "Your total is: " & curTotal
End Sub


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Take a look at the Northwind sample database that comes with MS Office/Access. There is are Orders and Order Details tables in the sample with forms, reports,...

I'm not criticizing what you have done so far since I often test and learn stuff for a very specific purpose that I would not use in an application.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top