Results 1 to 9 of 9
  1. #1
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186

    Save information to a table from an unbound textbox

    Hi everyone,

    Into my form called "Form1" there is two unbounded Textboxes (not related to the original table - "main1tbl") called "TextBox1" and "TextBox2" and also a command buttom called "Savecmd".

    The event I would like to create is "Savecmd_Onclick" and when the users would type information into "TextBox1" and "TextBox2", and then after click on "Savecmd" that information would be saved into the table "Recordtbl" at the fields "Field1" (TextBox1) and "Field2" (TextBox2)



    Could somebody help me on this with the code?

    I really appreciate your help!

  2. #2
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Just bind the text box mate. make sure your fields are included in the data source of your form. then select the field you need in the text box.

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Does the form use the Recordtbl table as a RecordSource?

  4. #4
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    No, in fact the table Recordtbl is independient from the form1 and from the table "maintbl"

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    There are a couple things that need to be clarified. First, are you trying to append a record to Recordtbl or are you trying to UPDATE an existing record within Recordtbl? If the latter, you will need to define which record by including criteria on your VBA statement.

    If the former, you could use an SQL statement to INSERT INTO.

    Something like
    Code:
    dim strSQL as string
    strSQL = "INSERT INTO Recordtbl (Field1, Field2) VALUES(" & Me.TextBox1 & ", " & Me.TextBox2 & ")"
    currentdb.execute strSQL

  6. #6
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    I would like to append the information, I tried with the code but it shows an error on "currentdb.execute strsSQL"

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    The code I provided is for Numeric values. Here is a text version
    strSQL = "INSERT INTO Recordtbl (Field1, Field2) VALUES ('" & Me.TextBox1 & "', '" & Me.TextBox2 & "')"

  8. #8
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    That is exactly what I was looking for!!!

    I really appreciate your help!!!!

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    No problem. It is advisable that you add some code to verify there is actual data in the textboxes before attempting the append and that the append, if that line is executed, was a success. Writing code to do stuff is the easy part. The big job is writing code to make sure everything is running smoothly.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2015, 01:24 PM
  2. Replies: 8
    Last Post: 04-12-2013, 08:59 PM
  3. Replies: 3
    Last Post: 10-08-2012, 08:40 AM
  4. Save data from textbox to table
    By GrayWolf in forum Access
    Replies: 7
    Last Post: 03-27-2012, 09:21 AM
  5. Replies: 13
    Last Post: 09-14-2011, 07:19 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