Click here to Skip to main content
15,891,920 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a save button called SvnNew, I want when clicked should first check value of Issue_Qntty,if value of Issue_Qntty is less than the value of INStock, then it should run my Updatequery and save the Issue, else it should simply give out an error message. with the piece code here I was expecting it to do but unlucky enough it doesn't, what it does is simply saving the transaction no matter if the Issue_Qntty value is greater than INStock value. Could you guys help me out to find where i am wrong? Thanx in advance!

VB
Private Sub SvnNew_Click()
If [Forms]![Issue]![Issue_Qntty] < [Forms]![Issue]![INStock] Then
 DoCmd.SetWarnings False
 DoCmd.OpenQuery "updateqry", acViewNormal, acEdit
 DoCmd.SetWarnings True
 DoCmd.Save
 MsgBox ("saved sucessful")
        DoCmd.Close acDefault
         DoCmd.OpenForm "Issue", acNormal
       'ElseIf [Forms]![Issue]![Issue_Qntty] > [Forms]![Issue]![INStock] Then
'MsgBox ("invalid value")
Else
MsgBox ("invalid value")
End If
         
End Sub
Posted
Updated 24-Jan-14 23:29pm
v3
Comments
Richard MacCutchan 25-Jan-14 5:31am    
Use your debugger to check the values of Issue_Qntty and INStock when the buttom is clicked.
CPallini 25-Jan-14 5:42am    
Virtual 5.
Another option would be 'hand-crafted-debug', that is assigning those quantities to integer variables and printing out the values of such integer variables.
WhiteTulip 25-Jan-14 6:28am    
i'v tried to use that, then i saw this, example Issue_Qntty = 1 while INStock = "0"
can these quotes be the reason that it fails to compare between the two values? and the value in textbox INStock is automatically copied from a multi valued combo box as follows, =[medcbo].[column](2). this mean when one selects medicine in medcbo combo box it automatically copies the its values in store into textbox INStock. then when one writes the number he wants to issue = Issue_Qntty, it compares the two values.
Richard MacCutchan 25-Jan-14 7:09am    
There is your problem, you are trying to do numeric comparisons on a value that is a string. You need to ensure all values are of the same type. The value from the textbox or combo must be parsed or otherwise converted to an integer before doing the compare.
WhiteTulip 25-Jan-14 11:18am    
thanx alot, i just tried to make textbox that carries INStock value coping its values dirrect from the table stored instead. That made it. And when tried to check with debugger, they were all numbers, no quotes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900