Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Freddie81 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2018
    Posts
    149

    save value in textbox to field in table

    How would I go about saving the value of a txtbox to a field in a table without setting the txtbox source to the field in property sheet?
    Example:
    I have a form calculating totals. I have an unbound textbox to display the value of the Dsum function. Now I need that textbox to save the vale to the field in my table.
    Table is InvoiceT
    Field is IBalance


    Textbox is txtTempInvBalance

    I tried:
    [InvoiceT.IBalance] = Me.txtTempInvBalance
    but It kicks error saying you cant assign a value to this object

    Any advice for me ?

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Use update query or SQL:

    dim sSQL as string
    sSQL="UPDATE InvoiceT SET IBalance = " & Me.txtTempInvBalance
    CurrentDB,Execute sSQL,dbFailOnError

  3. #3
    Freddie81 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2018
    Posts
    149
    CurrentDb.Execute sSQL, dbFailOnError givs syntax error when I run it

  4. #4
    Freddie81 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2018
    Posts
    149
    Click image for larger version. 

Name:	error01.JPG 
Views:	6 
Size:	25.0 KB 
ID:	34113Click image for larger version. 

Name:	error02.JPG 
Views:	6 
Size:	41.4 KB 
ID:	34114

    This is what I get nd the debug screen

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    What is the datatype for IBalance field you are updating?

    Also the Form_Open event isn't appropriate as the form hasn't fully loaded
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    Freddie81 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2018
    Posts
    149
    IBalance is number type and format in table is Double
    I do not really have a clue what event does what so I assumed it would be the correct one. What in your opinion would be the correct event?

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Ok so the sql should be fine once the form is fully loaded

    Try placing at the end of the form load event
    Also add the line DoEvents just before the sSQL line to ensure previous code has completed

    If it still errors, then I'd place the code in a button click event
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    Freddie81 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2018
    Posts
    149
    Moved it to the On Load Event and added the DoEvents line. Still getting the error. "Syntax error in UPDATE statement

  9. #9
    Freddie81 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2018
    Posts
    149
    I have even tried :

    DoCmd.RunSQL ("UPDATE InvoiceT SET IBalance= " & Me.txtInvBalance & ";")
    Getting the same error

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Ok try adding the line Debug.Print sSQL before the Execute line and post the result you see in the VBE Immediate window
    If you get an error, check the DSum and possibly surround with Nz(....,0)
    You might also CHANGE to "InvoiceID=" & me.InvoiceID

    Also, have you checked the field, table and control names are correct.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Try moving the below lines to the Form_Current event:
    Code:
    Dim sSQL as string
    sSQL = "Update  InvoiceT SET IBalence = " & txtInvBalance
    debug.print sSQL
    Currentdb.execute sSQL, dbFailOnError
    As Colin noted, if it still fails, it's probably because
    1. InvoiceT is misspelled or is not a table at all, or IBalance is not a field in that table
    2. txtInvBalance holds an invalid value.
    3. Ibalance is not a numeric field in the table.
    The debug.print should show you the actual value of txtInvBalance being used, as well as you being able to see it on the form.

    Edit:
    Rereading your posts, I see that the source control name for the update is sometimes txtTempInvBalance and sometimes txtInvBalance. Only one is correct.

  12. #12
    Freddie81 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2018
    Posts
    149
    Ridders52, the Immediate window shows UPDATE InvoiceT SET IBalance= -20. This is the same amount my Dsum gives so Dsmu is working like it should

    All the names are correct for Field, Table and control...just double checked

    "

  13. #13
    Freddie81 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2018
    Posts
    149
    Davegri...the table does exist and is spelled correctly as does IBalance. txtInvBalance displays the correct information as per Dsum. I used MsgBox to display each Variable and they all check out. IBalance is a number field but it is formatted to Double.

  14. #14
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Try this
    Code:
    CurrentDB.Execute "UPDATE InvoiceT SET InvoiceT.IBalance = " & Me.txtInvBalance, dbfailonerror
    If it still fails, then despite your checks, something must be spelt wrongly or there is a reference issue or a compile error.
    Did you add Nz
    You could try form current or a button click event as already suggested but I don't think that's the issue
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  15. #15
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Well, that exhausts our offhand ideas. We need to see the database. If it holds sensitive data, post a copy with a couple of phony entries to demonstrate the problem.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 03-28-2017, 07:31 AM
  2. Replies: 8
    Last Post: 12-03-2015, 10:18 AM
  3. Save data from textbox to table
    By GrayWolf in forum Access
    Replies: 7
    Last Post: 03-27-2012, 09:21 AM
  4. Replies: 13
    Last Post: 09-14-2011, 07:19 AM
  5. Replies: 4
    Last Post: 01-05-2011, 07:56 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