SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Other Forums
 MS Access
 Sub not performing as expected
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

djbomb95
Starting Member

9 Posts

Posted - 09/07/2012 :  23:57:25  Show Profile  Reply with Quote
Private Sub btnAddPizza_Click()

Dim strBase As String
Dim strSize As String
Dim intPrice As Integer
Dim intSizeError As Integer
Dim intBaseError As Integer

Tryagain:

strSize = InputBox("Type the size. Either:" & vbNewLine & "1 for small " & vbNewLine & "2 for Medium " & vbNewLine & "3 for Large", "Choose Size")
If strSize = "1" Then
intPrice = 6
ElseIf strSize = "2" Then
intPrice = 7
ElseIf strSize = "3" Then
intPrice = 8
Else
strSizeError = MsgBox("You must enter either 1, 2 or 3. Try Again?", vbYesNo, "Oops!")
If strSizeError = vbYes Then
GoTo Tryagain
Else
GoTo NoPizza
End If
End If


Tryagain2:

strBase = InputBox("Type the name of the base. Either:" & vbNewLine & "1 for Cheesy " & vbNewLine & "2 for Classic" & vbNewLine & "3 for Thin", "Choose Base")
If strBase = "1" Then
intPrice = intPrice + 1
ElseIf strSize = "2" Then
intPrice = intPrice
ElseIf strSize = "3" Then
intPrice = intPrice
Else
strSizeError = MsgBox("You must enter either 1, 2 or 3. Try Again?", vbYesNo, "Oops!")
If strBaseError = vbYes Then
GoTo Tryagain2
Else
strSize = ""
GoTo NoPizza
End If
End If


If strBase = "1" Then
strBase = "Cheesy"
ElseIf strSize = "2" Then
strBase = "Classic"
ElseIf strSize = "3" Then
strBase = "Thin"
End If

If strSize = "1" Then
strSize = "S"
ElseIf strSize = "2" Then
strSize = "M"
ElseIf strSize = "3" Then
strSize = "L"
End If


DoCmd.RunSQL "INSERT INTO PizzaOrder (PizzaName, PizzaBase, OrderID, Special, PizzaSize, Price) VALUES ('" & lstPizzaMenu & "', '" & strBase & "', " & txtOrderID & ", No, '" & strSize & "', " & intPrice & ");"
lstPizzasAdded.Requery
NoPizza:

End Sub

This sub does work on the condition that both input boxes have the same values put into them. Basically, I click the button, and two boxes pop up saying enter your value. You type in 1, 2 or 3 for small to large respectively and you type the same for cheesy to thin aswell. This basically gathers all the information that isn't already on the form to insert a row into my table. As I said before, it does work if both values are the same (I have to type 1 in the first box and 1 in the second). Is there any way anyone knows to fix this?

chadmat
The Chadinator

USA
1974 Posts

Posted - 09/08/2012 :  00:55:29  Show Profile  Visit chadmat's Homepage  Reply with Quote
What happens if they are not the same? Can you set a breakpoint and step thru it and see what is hapening?

-Chad
Go to Top of Page

djbomb95
Starting Member

9 Posts

Posted - 09/08/2012 :  02:44:18  Show Profile  Reply with Quote
Hey there Chad, I have just taken a long hard glance at the code, and I have found that I must have copied and pasted but not transposed, because the second Select Case statement is not not consistently strBase, it has two of the strSize in it. I have fixed this issue, but I will post again in this thread if I come across other problems in relation to this sub. Thanks for the guidance, it was through analysing properly that I found the error.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000