Add To Table From Text Box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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 said:
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
 
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 said:
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 said:
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
 
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 hel

----- 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 said:
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 "')
if no existing record already matches your textbox, you're no
insertin
anything
try this, instead of the docmd.query, run this line of code
currentdb.execute "insert into airportlist (airport) values (" me.text13 &> "') I am trying to set up a way to add a value to a field in a tabl
from
text box in a form. I have set up an append query, and have the cod to ru
the append query from a command button. It doesn't give me any erro
messagges but it doesn't add any data to the table. Here is the cod that
have
Private Sub Command6_Click( DoCmd.SetWarnings Fals
DoCmd.OpenQuery "AddAirport Me![Text13] = "
DoCmd.SetWarnings Tru End Su
This should take the value trom "text box 13" and add it to th
table b
using the append query. Below is the SQL for my append query
INSERT INTO AirportList ( Airport
SELECT AirportList.Airpor
FROM AirportLis
WHERE (((AirportList.Airport)=[Forms]![AddAirport]![Text13]))
I am not sure where I am going wrong with this. Any help would b appreciated
Thank
 
"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

(no e-mails, please!)


David Kane said:
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 said:
I am getting an error message when I try using the line you
provided me,
it says that: not
inserting
anything.
try this, instead of the docmd.query, run this line of code:
(" &
me.text13 &> "')"
message
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.
 
Back
Top