Results 1 to 2 of 2
  1. #1
    zarfx4 is offline Novice
    Windows XP Access 2003
    Join Date
    May 2009
    Posts
    15

    VB to Increase record update by 1

    Hello.
    I have a form with multiple fields on it. We will call them SLO
    They are text boxes and there are 6 of them named SLO1, SLO2.....SLO6
    What I want to do, is use VB to update each as a string to a table individually. But Id like to only type the code once, and use a DO WHILE and increase the value by one.
    Example.
    Current Code looks like this:
    Private Sub UpdateButton_Click()
    Set rstNewInventoryDataRecord = CurrentDb.OpenRecordset("Select * FROM MetricData")
    Set CurrentForm = Screen.ActiveForm

    Dim Counter As Integer
    Counter = 1
    rstNewInventoryDataRecord.AddNew
    rstNewInventoryDataRecord.SLO = CurrentForm.SLOT1.Caption
    rstNewInventoryDataRecord.Update


    MsgBox "Update Complete"
    End Sub

    What I want to do is use the counter to increase by one after each loop and stop after 6.
    So...Do while Counter < 7
    and incease the CurrentForm.SLOT1.Caption by one each time.
    Ive tried
    rstNewInventoryDataRecord.SLO = CurrentForm.SLOT & Counter.Caption
    and
    rstNewInventoryDataRecord.SLO = CurrentForm."SLOT" & Counter.Caption
    as well as a few other ideas all to no avail
    Is this possible? Surely it has to be???
    Suggestions?
    Many Thanks!

  2. #2
    zarfx4 is offline Novice
    Windows XP Access 2003
    Join Date
    May 2009
    Posts
    15
    Never Mind...got it figured out:


    Your the man!!!! Go it all figured out....

    Option Compare Database
    Private Sub UpdateButton_Click()
    Set rstNewInventoryDataRecord = CurrentDb.OpenRecordset("Select * FROM MetricData")

    Dim CurrentForm As Form
    Dim Counter As Integer
    Counter = 1
    Set CurrentForm = Screen.ActiveForm
    Do While Counter < 7
    rstNewInventoryDataRecord.AddNew
    rstNewInventoryDataRecord.SLOCOUNT = Counter
    rstNewInventoryDataRecord.SLO = CurrentForm("SLOT" & Counter).Caption
    rstNewInventoryDataRecord.ValueDateMonth = Month(CurrentForm("SLOD" & Counter))
    rstNewInventoryDataRecord.ValueDateYear = Year(CurrentForm("SLOD" & Counter))
    rstNewInventoryDataRecord.Metric_Value = CurrentForm("SLO" & Counter)
    rstNewInventoryDataRecord.Update
    Counter = Counter + 1
    Loop
    MsgBox "Update Complete"

    End Sub

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

Similar Threads

  1. increase running query speed
    By afshin in forum Queries
    Replies: 1
    Last Post: 10-15-2011, 12:36 PM
  2. Increase Size of Field Name
    By tonere in forum Database Design
    Replies: 5
    Last Post: 06-27-2011, 02:30 PM
  3. Increase number by 1
    By elstiv in forum Queries
    Replies: 2
    Last Post: 05-14-2011, 12:25 AM
  4. Increase by 1
    By Mclaren in forum Programming
    Replies: 5
    Last Post: 08-23-2010, 10:53 PM
  5. Increase search speed
    By kjuelfs in forum Queries
    Replies: 3
    Last Post: 07-12-2010, 05:11 AM

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