insert into statement | | |
i have a question regarding the insert into statement in access 97 database.
i wrote a small insert statement for my new table def ("tblImportET") but when
i run the code, no records are appended to "tblImportET".
i thought that the "*" would select all of the fields and then
import into the "tblImportET".
any advice would be appreciated - thanks jung
here is the code:
Set dbsEtrack = CurrentDb
'Set rstET = ("Exception Tracking")
'step one: delete the tdf("tblImportET")
dbsEtrack.TableDefs.Delete ("tblImportET")
'step two: Create a new TableDef object.
Set tdfNew = dbsEtrack.CreateTableDef("tblImportET")
With tdfNew
.Fields.Append .CreateField("ET LN Shortname", dbText)
.Fields.Append .CreateField("ET Amount", dbCurrency)
.Fields.Append .CreateField("ET EC Code", dbText)
'.Fields.Append.CreateField("ET Number", dbLong) = rstET![ET Number] + 1
' Append the new TableDef object to the Etrack
' database.
dbsEtrack.TableDefs.Append tdfNew
End With
dbsEtrack.TableDefs.Refresh
'step three: insert data from qryBMODReport into "tblImportET"
' nothing happens
insertsql = ("INSERT INTO [tblImportET] SELECT * FROM [qryBMODReport]") | | | | re: insert into statement
"JMCN" <picarama@yahoo.fr> wrote in message
news:2772ee20.0312041356.7226b2e3@posting.google.c om...[color=blue]
> i have a question regarding the insert into statement in access 97[/color]
database.[color=blue]
> i wrote a small insert statement for my new table def ("tblImportET") but[/color]
when[color=blue]
> i run the code, no records are appended to "tblImportET".
> i thought that the "*" would select all of the fields and then
> import into the "tblImportET".[/color]
[snip]
This line...
insertsql = ("INSERT INTO [tblImportET] SELECT * FROM [qryBMODReport]")
....is not how you execute a SQL statement in code. You need either
DoCmd.RunSQL or the Execute method of a Database object. I prefer the
latter.
dbsEtrack.Execute "INSERT INTO [tblImportET] SELECT * FROM
[qryBMODReport]", dbFailOnError
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com | | | | re: insert into statement
JMCN,
Is there really a need to delete the tabledef? If so, you may need to do a
dbsEtrack.TableDefs.Refresh
after the table creation.
Alternatively, you don't have to create the tabledef that way at all. You
could just do
dbsEtrack.TableDefs.Delete ("tblImportET")
dbsEtrack.TableDefs.Refresh
dbsEtrack.Execute("SELECT * INTO tblImportET FROM [qryBMODReport];")
dbsEtrack.TableDefs.Refresh
"JMCN" <picarama@yahoo.fr> wrote in message
news:2772ee20.0312041356.7226b2e3@posting.google.c om...[color=blue]
> i have a question regarding the insert into statement in access 97[/color]
database.[color=blue]
> i wrote a small insert statement for my new table def ("tblImportET") but[/color]
when[color=blue]
> i run the code, no records are appended to "tblImportET".
> i thought that the "*" would select all of the fields and then
> import into the "tblImportET".
>
> any advice would be appreciated - thanks jung
> here is the code:
> Set dbsEtrack = CurrentDb
> 'Set rstET = ("Exception Tracking")
>
> 'step one: delete the tdf("tblImportET")
> dbsEtrack.TableDefs.Delete ("tblImportET")
>
> 'step two: Create a new TableDef object.
> Set tdfNew = dbsEtrack.CreateTableDef("tblImportET")
>
> With tdfNew
>
> .Fields.Append .CreateField("ET LN Shortname", dbText)
> .Fields.Append .CreateField("ET Amount", dbCurrency)
> .Fields.Append .CreateField("ET EC Code", dbText)
>
> '.Fields.Append.CreateField("ET Number", dbLong) = rstET![ET[/color]
Number] + 1[color=blue]
>
> ' Append the new TableDef object to the Etrack
> ' database.
> dbsEtrack.TableDefs.Append tdfNew
>
> End With
>
> dbsEtrack.TableDefs.Refresh
>
> 'step three: insert data from qryBMODReport into "tblImportET"
> ' nothing happens
> insertsql = ("INSERT INTO [tblImportET] SELECT * FROM[/color]
[qryBMODReport]") | | | | re: insert into statement
"DFS" <nospamDS@nospam.com> wrote in message news:<vsvbst5dl4rk42@corp.supernews.com>...[color=blue]
> JMCN,
>
>
> Is there really a need to delete the tabledef? If so, you may need to do a
>
> dbsEtrack.TableDefs.Refresh
>
> after the table creation.
>
> Alternatively, you don't have to create the tabledef that way at all. You
> could just do
>
> dbsEtrack.TableDefs.Delete ("tblImportET")
> dbsEtrack.TableDefs.Refresh
> dbsEtrack.Execute("SELECT * INTO tblImportET FROM [qryBMODReport];")
> dbsEtrack.TableDefs.Refresh
>
>[/color]
i thought i had to delete it for updated information. but since the
refresh pretty much takes care of updating the newer loan information,
no i don't need to :) thanks again for the help!!!!
[color=blue]
> "JMCN" <picarama@yahoo.fr> wrote in message
> news:2772ee20.0312041356.7226b2e3@posting.google.c om...[color=green]
> > i have a question regarding the insert into statement in access 97[/color]
> database.[color=green]
> > i wrote a small insert statement for my new table def ("tblImportET") but[/color]
> when[color=green]
> > i run the code, no records are appended to "tblImportET".
> > i thought that the "*" would select all of the fields and then
> > import into the "tblImportET".
> >
> > any advice would be appreciated - thanks jung
> > here is the code:
> > Set dbsEtrack = CurrentDb
> > 'Set rstET = ("Exception Tracking")
> >
> > 'step one: delete the tdf("tblImportET")
> > dbsEtrack.TableDefs.Delete ("tblImportET")
> >
> > 'step two: Create a new TableDef object.
> > Set tdfNew = dbsEtrack.CreateTableDef("tblImportET")
> >
> > With tdfNew
> >
> > .Fields.Append .CreateField("ET LN Shortname", dbText)
> > .Fields.Append .CreateField("ET Amount", dbCurrency)
> > .Fields.Append .CreateField("ET EC Code", dbText)
> >
> > '.Fields.Append.CreateField("ET Number", dbLong) = rstET![ET[/color]
> Number] + 1[color=green]
> >
> > ' Append the new TableDef object to the Etrack
> > ' database.
> > dbsEtrack.TableDefs.Append tdfNew
> >
> > End With
> >
> > dbsEtrack.TableDefs.Refresh
> >
> > 'step three: insert data from qryBMODReport into "tblImportET"
> > ' nothing happens
> > insertsql = ("INSERT INTO [tblImportET] SELECT * FROM[/color]
> [qryBMODReport]")[/color] | | | | re: insert into statement
"DFS" <nospamDS@nospam.com> wrote in message news:<vsvbst5dl4rk42@corp.supernews.com>...[color=blue]
> JMCN,
>
>
> Is there really a need to delete the tabledef? If so, you may need to do a
>
> dbsEtrack.TableDefs.Refresh
>
> after the table creation.
>
> Alternatively, you don't have to create the tabledef that way at all. You
> could just do
>
> dbsEtrack.TableDefs.Delete ("tblImportET")
> dbsEtrack.TableDefs.Refresh
> dbsEtrack.Execute("SELECT * INTO tblImportET FROM [qryBMODReport];")
> dbsEtrack.TableDefs.Refresh
>
>[/color]
i thought i had to delete it for updated information. but since the
refresh pretty much takes care of updating the newer loan information,
no i don't need to :) thanks again for the help!!!!
[color=blue]
> "JMCN" <picarama@yahoo.fr> wrote in message
> news:2772ee20.0312041356.7226b2e3@posting.google.c om...[color=green]
> > i have a question regarding the insert into statement in access 97[/color]
> database.[color=green]
> > i wrote a small insert statement for my new table def ("tblImportET") but[/color]
> when[color=green]
> > i run the code, no records are appended to "tblImportET".
> > i thought that the "*" would select all of the fields and then
> > import into the "tblImportET".
> >
> > any advice would be appreciated - thanks jung
> > here is the code:
> > Set dbsEtrack = CurrentDb
> > 'Set rstET = ("Exception Tracking")
> >
> > 'step one: delete the tdf("tblImportET")
> > dbsEtrack.TableDefs.Delete ("tblImportET")
> >
> > 'step two: Create a new TableDef object.
> > Set tdfNew = dbsEtrack.CreateTableDef("tblImportET")
> >
> > With tdfNew
> >
> > .Fields.Append .CreateField("ET LN Shortname", dbText)
> > .Fields.Append .CreateField("ET Amount", dbCurrency)
> > .Fields.Append .CreateField("ET EC Code", dbText)
> >
> > '.Fields.Append.CreateField("ET Number", dbLong) = rstET![ET[/color]
> Number] + 1[color=green]
> >
> > ' Append the new TableDef object to the Etrack
> > ' database.
> > dbsEtrack.TableDefs.Append tdfNew
> >
> > End With
> >
> > dbsEtrack.TableDefs.Refresh
> >
> > 'step three: insert data from qryBMODReport into "tblImportET"
> > ' nothing happens
> > insertsql = ("INSERT INTO [tblImportET] SELECT * FROM[/color]
> [qryBMODReport]")[/color] |  | Similar Microsoft Access / VBA bytes | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,584 network members.
|