Results 1 to 7 of 7
  1. #1
    LarryJ is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2023
    Posts
    18

    Another newbie question

    I created a form where I enter data, click a button and it fills other fields with the results of various calculations.


    I have another button to add the calculated results to an existing table.
    The insert statement is in this format:

    insert into tablename (list of table columns) values (field1.value, field2.value...)

    My question is, why does the form prompt me for the values in the fields? I thought using fieldnames.value would put the data on the table automatically.
    While I was typing that last line, I found myself wondering if I need to put single quotes around each of the fieldname.value members in the values list.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    You probably need to concatenate the control references into the string, but you haven't shown your code. The real question is why you aren't using a bound form?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    LarryJ is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2023
    Posts
    18
    Because I am new to Access programming and don't know what a bound form is. On a side note, I tried the single quotes around each field.value combo and I didn't have to enter the data, but it treated them all as a string. Clearly not what I was going for.
    Here is the code:

    Private Sub RosterAdd_Click()
    Dim SQL As String


    If IsNumeric(Me.IE.Value) Then
    SQL = "insert into All_Teams (Team, Pos, DEF, Name, BB, K, Clutch, Offense, HR, Triple, Spd, Gopher, Rate, IE, Rate2, Walk, Strikeout) values (me.TeamSelect.value,me.PositionSelect.value,me.DE F.value,me.PlayerName.value,me.BB.value, me.K.value,me.Clutch.value,me.Offense.value,me.HR. value,me.Triple.value,me.Spd.value,me.Gopher.value ,me.Rate.value.me.IE.value,me.Rate2.value,me.Walk. value,me.Strikeout.value)"
    Else
    SQL = "insert into All_Teams (Team, Pos, DEF, Name, BB, K, Clutch, Offense, HR, Triple, Spd) values (me.TeamSelect.value,me.PositionSelect.value,me.DE F.value,me.PlayerName.value,me.BB.value,me.K.value ',me.Clutch.value,me.Offense.value,me.HR.value,me. Triple.value,me.Spd.value)"
    End If
    'Debug.Print SQL
    DoCmd.RunSQL SQL
    End Sub

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    See if this helps:

    http://www.baldyweb.com/BuildSQL.htm

    but I'd almost certainly use a bound form. That is a form with a record source that is either the target table or a query of that table. You are doing this the hard way.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,283
    Look on youtube. Plenty of videos on access there.
    https://www.youtube.com/watch?v=l75G...dW5kIGZvcm0%3D
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    LarryJ is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2023
    Posts
    18
    Quote Originally Posted by pbaldy View Post
    See if this helps:

    http://www.baldyweb.com/BuildSQL.htm

    but I'd almost certainly use a bound form. That is a form with a record source that is either the target table or a query of that table. You are doing this the hard way.
    I got it to work, thanks to your link.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Glad it worked for you. When you need to edit records, you may reconsider the bound form approach.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. newbie question
    By sbrady19 in forum Access
    Replies: 4
    Last Post: 02-10-2015, 01:25 PM
  2. Newbie question
    By Brevik1 in forum Access
    Replies: 1
    Last Post: 04-05-2014, 10:26 AM
  3. vba question from newbie
    By ninachopper in forum Access
    Replies: 17
    Last Post: 07-29-2010, 01:22 PM
  4. Newbie question
    By webby in forum Access
    Replies: 6
    Last Post: 07-19-2010, 06:22 AM
  5. Newbie question
    By The_Dude in forum Programming
    Replies: 2
    Last Post: 12-23-2007, 07:11 PM

Tags for this Thread

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