Results 1 to 2 of 2
  1. #1
    Wafula is offline Novice
    Windows XP Access 2007
    Join Date
    May 2015
    Posts
    1

    Question How to Update Data in a specific row based on the Primary Key Field data in the same table

    Dear All,



    I'm a new programmer using VB 2005 Professional and trying to auto increment the StyleNumber integer field by 1 every time I create a new product but this in not happening. What could I be doing wrong?
    The table has the following fields?

    CategoryID, CategoryName, StyleNumber
    01A DRY FOODS 9
    01B FRESH FOOD 4
    02A BODY CARE PRODUCTS 3

    the saving code is a follows:

    Dim NRec As Integer
    For NRec = 0 To CategoryTable.Rows.Count - 1
    If CategoryTable.Rows(NRec).Item("CategoryName").ToSt ring = cboCategory.Text.ToString Then
    StockCode = CSng(CategoryTable.Rows(NRec).Item("StyleNumber"))
    Exit For
    End If
    Next

    With CategoryCommand
    .Connection = InventoryConnection
    .CommandText = "UPDATE Category SET StyleNumber=StyleNumber+'" & 1 & "'WHERE CategoryID='" & cboCategory.SelectedValue.ToString & "'"
    .ExecuteNonQuery()
    End With


    Please help me resolve this problem

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I do not know if I am following all of your code correctly or not but it seems you are not getting the UPDATE within the scope of your For NRec loop.

    Maybe try bringing your CommandText method within your loop.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 01-09-2015, 05:48 PM
  2. Replies: 1
    Last Post: 04-24-2014, 06:31 AM
  3. Replies: 3
    Last Post: 06-19-2013, 02:39 PM
  4. Replies: 5
    Last Post: 05-22-2013, 12:38 PM
  5. Replies: 1
    Last Post: 09-02-2010, 03:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums