Re: Add To Table From Text Box
From: Douglas J. Steele (NOSPAM_djsteele_at_NOSPAM_canada.com)
Date: 05/25/04
- Next message: Ken: "Syntax Error"
- Previous message: Chris Nebinger: "Network application"
- In reply to: David Kane: "Re: Add To Table From Text Box"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 25 May 2004 18:52:27 -0400
"insert into airportlist (airport, field2) values (' " & me.text13 & " ', "
& me.text14 & ") "
This assumes field2 is numeric. If it's text, you'll need the extra quotes
like for the first field.
By the way, you'll run into problems with the code above if the text
contains an apostrophe (such as O'Hare). You'll either need to change the
code to:
"insert into airportlist (airport) values (" & Chr$(34) & me.text13 &
Chr$(34) & ") "
or
"insert into airportlist (airport) values ('" & Replace(me.text13, "'",
"''") & "') "
Exagerated for clarity, that last one is:
"insert into airportlist (airport) values (' " & Replace(me.text13, " ' ", "
' ' ") & " ' ) "
-- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "David Kane" <anonymous@discussions.microsoft.com> wrote in message news:5E45396F-6998-4962-B4D1-15C9619A8354@microsoft.com... > That seemed to take care of the issue perfectly. I do have one more question that you may be able to help me with. It is along these same lines. If I have two textboxes and I want to add one of the values to one field and the other one to another field, is there a way to do this. Can I use what you have already provided me and simply put an AND somewhere. > > Thanks for all your help > > ----- Steve Conklin (Dev@UltraDNT) wrote: ----- > > missing a single quote, it looks like ... > try this (spacess added between signles and doubles for clarity): > > "insert into airportlist (airport) values (' " & me.text13 & " ') " > > > > > "David Kane" <anonymous@discussions.microsoft.com> wrote in message > news:7A22A9CA-B358-4F42-B712-1C6771D04CBF@microsoft.com... > > I am getting an error message when I try using the line you provided me, > it says that: > >> Run Time Error '3075' > >> Syntax error in string in query expression "'). > >>> Do you have any suggestions as to what I may be doing wrong. > >> Thanks > >>> ----- Steve Conklin (Dev@UltraDNT) wrote: ----- > >> if no existing record already matches your textbox, you're not > inserting > > anything. > > try this, instead of the docmd.query, run this line of code: > >> currentdb.execute "insert into airportlist (airport) values (" & > me.text13 &> "')" > >>> "David Kane" <anonymous@discussions.microsoft.com> wrote in message > > news:D1C5B379-9B7E-45B3-8459-38D5EC41E4BD@microsoft.com... > >> I am trying to set up a way to add a value to a field in a table > from a > > text box in a form. I have set up an append query, and have the code > to run > > the append query from a command button. It doesn't give me any error > > messagges but it doesn't add any data to the table. Here is the code > that I > > have. > >>> Private Sub Command6_Click() > >> DoCmd.SetWarnings False > >>> DoCmd.OpenQuery "AddAirport" > >> Me![Text13] = "" > >>> DoCmd.SetWarnings True > >> End Sub > >>> This should take the value trom "text box 13" and add it to the > table by > > using the append query. Below is the SQL for my append query. > >>> INSERT INTO AirportList ( Airport ) > >> SELECT AirportList.Airport > >> FROM AirportList > >> WHERE (((AirportList.Airport)=[Forms]![AddAirport]![Text13])); > >>> I am not sure where I am going wrong with this. Any help would be > > appreciated. > >>> Thanks > >>>
- Next message: Ken: "Syntax Error"
- Previous message: Chris Nebinger: "Network application"
- In reply to: David Kane: "Re: Add To Table From Text Box"
- Messages sorted by: [ date ] [ thread ]