Solved

VISUAL BASIC CODE FOR UPDATING QUANTITY OF PRODUCT!!

Posted on 2004-04-14
19
307 Views
Last Modified: 2013-11-25
OK I have a Form called frmProducts with numerous feilds including one called ItemsinStock.

I also have a command button, I want some code so that when i press the button the ItemsinStock is updated, in effect 1 is taken away. Also i want the code to pop up a message saying that the you should order some more items when the ItemsinStock = 2.

Also i have a text box next to the ItemsInStock called "NumberOfNewItems", and also have an update command button, i want some code so that when this update button is pressed the Number in the NumberOfNewItems Textbox is added to the ItemsInStock Textbox.

Hope you understand that.

Much appreciated

THANKS
0
Comment
Question by:Jam90
  • 11
  • 8
19 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 10826916
What is your table name? and field names?
that you want updated.

0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 10826939
<Also i want the code to pop up a message saying that the you should order some more items when the ItemsinStock = 2.>

You have to add a field on your table and set the value for MinQty.
0
 

Author Comment

by:Jam90
ID: 10827035
Table Name = tblProducts

Field Names Iwant updated are "Quantity"

FOr the pop up message cannot it just be done in VB and the minimum value be set in the code itself rather than making a textbox??
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 10827154
<FOr the pop up message cannot it just be done in VB and the minimum value be set in the code itself rather than making a textbox??>

Do you only have one particular item on your tblProducts?
And you are not going to add a textbox, You need to add a field to your tblProducts
Let us say your tblproducts has Item, Quantity as fields
tblProducts
Item        Quantity        MinQty << you have to add this
AAA            5                  2
BBB             15                3

getting the idea?
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 10827234
<
I also have a command button, I want some code so that when i press the button the ItemsinStock is updated, in effect 1 is taken away>

For this you can use

UPDATE tblProducts SET tblProducts.Quantity = [tblProducts].[Quantity]-1 ;
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 10827323
Can you please post the field names of tblProducts.
0
 

Author Comment

by:Jam90
ID: 10827422
Hi there i dont really want to create a new feild minQty as i am assuming that all the MinQtys arethe same for all prodcuts.

THanks
0
 

Author Comment

by:Jam90
ID: 10827453
For this statement it keeps sayin Syntax error

UPDATE tblProducts SET tblProducts.Quantity = [tblProducts].[Quantity]-1 ;
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 10827755
Jam90,
Ok how are you using it ? PLEASE paste the codes you are using.

PLEASE post the names of fields from tblProducts, we need the unique ID of the item for the update.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Jam90
ID: 10827904
I am using it like so..

Private Sub Command12_Click()

UPDATE tblProducts SET tblProducts.Product Quantity = [tblProducts].[Product Quantity]-1 ;

End Sub

TBLPRODUCTS FIELDS

Prodcut ID
Prodcut Name
Prodcut Price
Product Description
Prodcut Size
Images
Prodcut Quantity
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 10828020
Private Sub Command12_Click()
Dim sSQL as String

sSQL ="UPDATE tblProducts SET tblProducts.Product Quantity = [tblProducts].[Product Quantity]-1 " & _
           "Where tblProducts.ProductID= Forms.frmProducts.TextboxForProductID; "
'--------------------------------------------------------------------^^^^^^^^ change this to the name of textbox
CurrentDb.Execute sSQL,dbFailOnError



End Sub
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 10828033
Oops missed two[ ]

Private Sub Command12_Click()
Dim sSQL as String

sSQL ="UPDATE tblProducts SET tblProducts.[Product Quantity] = [tblProducts].[Product Quantity]-1 " & _
           "Where tblProducts.ProductID= Forms.frmProducts.TextboxForProductID; "
'--------------------------------------------------------------------^^^^^^^^ change this to the name of textbox
CurrentDb.Execute sSQL,dbFailOnError



End Sub
0
 

Author Comment

by:Jam90
ID: 10828055
I get sytax Error On  CurrentDb.Execute sSQL, dbFailOnError


Private Sub Command12_Click()

Dim sSQL As String

sSQL = "UPDATE tblProducts SET tblProducts.Product Quantity = [tblProducts].[Product Quantity]-1 " & _
           "Where tblProducts.Product ID= Forms.frmProducts.Product ID; "

CurrentDb.Execute sSQL, dbFailOnError

End Sub
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 10828362
Copy and paste this

Private Sub Command12_Click()
Dim sSQL As String
       
If Me.[Product ID] = DLookup("[Product ID]", "tblProducts", "[Product Quantity]= 3") Then
    MsgBox "Order Now"
End If
sSQL = "Update tblProducts Set tblProducts.[Product Quantity]= tblProducts.[Product Quantity]-1 "
sSQL = sSQL & "Where (tblProducts.[Product Id]) = " & (Me![Product ID])
        CurrentDb.Execute sSQL

End Sub
0
 

Author Comment

by:Jam90
ID: 10831545
OK Thanks thatworks OK.

However when i press the button i can only see the Product Qauntity go down by 1 after i click in thetext box?

Is there any wayof getting it to refresh everytime i clickthe button?

Also i wanted to put a text box next to the Prodcut Quantity Box, called "AddNewItemsToStock", so that when the user typed a number intothe box and clicked the command button it would add that number to "Product Quantity" Could you writesome code to do that?

THanks
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 10833119
using the same command button;

Private Sub Command12_Click()
Dim sSQL As String, sqlAdd As String, j As Long
If Me.AddNewItemsToStock <> "" Then
j = Me.AddNewItemsToStock
sqlAdd = "Update tblProducts Set tblProducts.[Product Quantity]= tblProducts.[Product Quantity]+ " & j & " "
sqlAdd = sqlAdd & "Where (tblProducts.[Product Id]) = " & Me![Product ID]
        CurrentDb.Execute sqlAdd
End If
       
If Me.[Product ID] = DLookup("[Product ID]", "tblProducts", "[Product Quantity]= 3") Then
    MsgBox "Order Now"
End If
sSQL = "Update tblProducts Set tblProducts.[Product Quantity]= tblProducts.[Product Quantity]-1 "
sSQL = sSQL & "Where (tblProducts.[Product Id]) = " & Me![Product ID]
        CurrentDb.Execute sSQL

End Sub
0
 

Author Comment

by:Jam90
ID: 10835034
Okone more question for the following code can you add a statement so that after it has updated the Product Quantity box it will remove the value in the AddNewItemsToStock text box.

THanks

Dim sSQL As String, sqlAdd As String, j As Long
If Me.AddNewItemsToStock <> "" Then
j = Me.AddNewItemsToStock
sqlAdd = "Update tblProducts Set tblProducts.[Product Quantity]= tblProducts.[Product Quantity]+ " & j & " "
sqlAdd = sqlAdd & "Where (tblProducts.[Product Id]) = " & Me![Product ID]
        CurrentDb.Execute sqlAdd
End If
       
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 485 total points
ID: 10835593
ok you can add this codes too

Private Sub Form_Load()
Me.AddNewItemsToStock = ""
End Sub


If Me.AddNewItemsToStock <> "" Then
j = Me.AddNewItemsToStock
sqlAdd = "Update tblProducts Set tblProducts.[Product Quantity]= tblProducts.[Product Quantity]+ " & j & " "
sqlAdd = sqlAdd & "Where (tblProducts.[Product Id]) = " & Me![Product ID]
        CurrentDb.Execute sqlAdd
Me.AddNewItemsToStock = ""     '<<<< add this line

End If


0
 

Author Comment

by:Jam90
ID: 10841191
THANKS
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now