none
Saving data in text boxes with SQL RRS feed

  • Question

  • Hi all,

    Another question:

    I have 20 Textboxes, named "Text1A, Text2A, Text3A, etc." where the user enters data. I want to save the data using a SQL statement "INSERT INTO".

    I have created a For...Next loop to save all 20 textbox data. The statement reads as follows:

    This statement gives an error.

    Is it possible to use as above, or do I need to create a field in the table for each textbox?

    The idea is to save 20 records in the table, which will uniquely be identified by the "LinkedCourseNumber".

    I trust the explanation is sufficient.

    Thanks

    Deon

    Friday, August 11, 2017 8:29 AM

Answers

  • Remove the "Me" qualifier from your reference:

    Forms!Frm_CourseRegistration("Text" & i & "A")

    You may need to refer to the Controls collection on the form:

    Forms!Frm_CourseRegistration.Controls("Text" & i & "A")


    -- Scott McDaniel, Microsoft Access MVP

    • Marked as answer by Deon SA Friday, August 11, 2017 4:36 PM
    Friday, August 11, 2017 12:02 PM
  • Remove the Me if calling from another form, otherwise remove the Forms!... And simply is the Me. Syntax instead.

    Daniel Pineault, 2010-2017 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    • Marked as answer by Deon SA Friday, August 11, 2017 4:36 PM
    Friday, August 11, 2017 12:49 PM

All replies

  • Why not simply build a continuous form?

     

    Regardless of the above, below is the basic syntax I've always used for iterating through a series of sequentially named controls

    Me("Text" & i)

    or, in your case

    Me("Text" & i & "A")

     

    Also, for this type of things, your best bet is to build the SQL statement and then Debug.Print it.  Then you can copy/paste it in the query editor to troubleshoot what the exact issue is.


    Daniel Pineault, 2010-2017 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net



    Friday, August 11, 2017 10:03 AM
  • Hi Daniel,

    There is a lot of other data also on the form that needs to be saved. All the data is entered into text boxes. For each group of data, I created textboxes named "Text1A, etc." for the one group and then "Text2A, etc" for then next group.

    Also, the user enters the data on one form, then moves on to another form. Some more data is entered on the 2nd form. On the 2nd form, is the "Save" button.

    Thus the SQL statement looks like below. Your suggestion "Me("Text" & i & "A")" still give the same error. Maybe something to do with the form where the data is entered:

    Friday, August 11, 2017 10:24 AM
  • Remove the "Me" qualifier from your reference:

    Forms!Frm_CourseRegistration("Text" & i & "A")

    You may need to refer to the Controls collection on the form:

    Forms!Frm_CourseRegistration.Controls("Text" & i & "A")


    -- Scott McDaniel, Microsoft Access MVP

    • Marked as answer by Deon SA Friday, August 11, 2017 4:36 PM
    Friday, August 11, 2017 12:02 PM
  • Remove the Me if calling from another form, otherwise remove the Forms!... And simply is the Me. Syntax instead.

    Daniel Pineault, 2010-2017 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    • Marked as answer by Deon SA Friday, August 11, 2017 4:36 PM
    Friday, August 11, 2017 12:49 PM
  • Thanks guys, my problem solved!!

    Regards

    Deon

    Friday, August 11, 2017 4:35 PM