Connecting Tech Pros Worldwide Forums | Help | Site Map

insert into statement

JMCN
Guest
 
Posts: n/a
#1: Nov 12 '05
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]")

Rick Brandt
Guest
 
Posts: n/a
#2: Nov 12 '05

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


DFS
Guest
 
Posts: n/a
#3: Nov 12 '05

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]")


JMCN
Guest
 
Posts: n/a
#4: Nov 12 '05

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]
JMCN
Guest
 
Posts: n/a
#5: Nov 12 '05

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]
Closed Thread