Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2011
    Posts
    1

    Unanswered: Run time error 3113: cannot update "win percentage"; field not undateable

    hi all,

    hope someone can help. need some help with this. trying to run a SQL UPDATE in VBA for a DB i'm making.

    the code is as follows;

    Plrplayed = Nz(DLookup("[Games Played]", "[Players]", "[ID]" = "me.player1"), 0) + 1
    If Me.win1 = True Then Plrwin = Nz(DLookup("[Games Won]", "[Players]", "[ID]" = "me.player1"), 0) + 1
    If Me.win1 = False Then Plrwin = DLookup("[Games Won]", "[Players]", "[ID]" = "me.player1")
    If Me.win1 = False Then Plrlose = Nz(DLookup("[Games Lost]", "[Players]", "[ID]" = "me.player1"), 0) + 1
    If Me.win1 = True Then Plrwin = Nz(DLookup("[Games Won]", "[Players]", "[ID]" = "me.player1"), 0)
    Plrwinperc = Plrwin / Plrplayed
    Plrwinperc = Plrwinperc * 100

    strSQL = "UPDATE Players SET [Games Played] = (Plrplayed) WHERE [ID] = player1 ;"
    DoCmd****nSQL strSQL
    strSQL = "UPDATE Players SET [Games Won] = (Plrwin) WHERE [ID] = player1;"
    DoCmd****nSQL strSQL
    strSQL = "UPDATE Players SET [Games Lost] = (Plrlose) WHERE [ID] = player1 ;"
    DoCmd****nSQL strSQL
    strSQL = "UPDATE Players SET [Win Percentage] = (Plrwinperc) WHERE [ID] = player1 ;"
    DoCmd****nSQL strSQL


    error is in the red line.

    also, my variables dont seem to be being read in the SQL comand, it's asking me for a value instead.

    Hope someone can help me!

    Richard

  2. #2
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    If Me.win1 = True Then Plrwin = Nz(DLookup("[Games Won]", "[Players]", "[ID]" = "me.player1"), 0) + 1
    If Me.win1 = False Then Plrwin = DLookup("[Games Won]", "[Players]", "[ID]" = "me.player1")
    If Me.win1 = False Then Plrlose = Nz(DLookup("[Games Lost]", "[Players]", "[ID]" = "me.player1"), 0) + 1
    If Me.win1 = True Then Plrwin = Nz(DLookup("[Games Won]", "[Players]", "[ID]" = "me.player1"), 0)
    Since you have 3 scenarios initializing Plrwin, and only 1 scenario initializing Plrlose, I would guess that in some cases Plrwin is value 0, or worse, null. Try changing the multiple if statements to If-Then-Else constuct. You can also go into debug mode (or add a Debug.Print statement after each if statement) and evaluate the result of each if statement before sending the result to the division.

    Sam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •