Group:  Microsoft Access ยป microsoft.public.access.modulesdaovba
Thread: Code not working correctly

Geek News

Code not working correctly
kateri4482 12/29/2008 5:49:01 PM
I have the following code running from a command button, and it ignores the
section after the "&" sign in the strTableName statement, so it just gives me
a Table called tblBackupEnhancedCodes without the date. I can't figure out
what I am doing wrong. I want to run this periodically and create a backup
of a table but add the current date to the end of it.

Dim strTableName As String, strSQL As String

strTableName = "tblBaclupEnhancedCodes" & Format(Date, "ddmmmmyy")

strSQL = "Select tblEnhancedCodes.* Into " & strTableName & " From
tblEnhancedCodes;"

CurrentDB.Execute strSQL, dbFailOnError

I hope this makes sense and any assistance is appreciated.



Re: Code not working correctly
Marshall Barton <marshbarton[ at ]wowway.com> 12/29/2008 6:15:13 PM
kateri4482 wrote:

[Quoted Text]
>I have the following code running from a command button, and it ignores the
>section after the "&" sign in the strTableName statement, so it just gives me
>a Table called tblBackupEnhancedCodes without the date. I can't figure out
>what I am doing wrong. I want to run this periodically and create a backup
>of a table but add the current date to the end of it.
>
>Dim strTableName As String, strSQL As String
>
>strTableName = "tblBaclupEnhancedCodes" & Format(Date, "ddmmmmyy")
>
>strSQL = "Select tblEnhancedCodes.* Into " & strTableName & " From
>tblEnhancedCodes;"


You probably have a text box named Date and its value is
Null.

If so, it's just another reminder not to use reserved words
when you make up names.

--
Marsh
MVP [MS Access]
Re: Code not working correctly
kateri4482 12/29/2008 9:49:01 PM
That is exactly the case. When I originally set up the table I had a field
called "Date" until I realized that is not a good idea, so I created a new
field but forgot to delete the old one. Thanks for the help!

"Marshall Barton" wrote:

[Quoted Text]
> kateri4482 wrote:
>
> >I have the following code running from a command button, and it ignores the
> >section after the "&" sign in the strTableName statement, so it just gives me
> >a Table called tblBackupEnhancedCodes without the date. I can't figure out
> >what I am doing wrong. I want to run this periodically and create a backup
> >of a table but add the current date to the end of it.
> >
> >Dim strTableName As String, strSQL As String
> >
> >strTableName = "tblBaclupEnhancedCodes" & Format(Date, "ddmmmmyy")
> >
> >strSQL = "Select tblEnhancedCodes.* Into " & strTableName & " From
> >tblEnhancedCodes;"
>
>
> You probably have a text box named Date and its value is
> Null.
>
> If so, it's just another reminder not to use reserved words
> when you make up names.
>
> --
> Marsh
> MVP [MS Access]
>
Re: Code not working correctly
Marshall Barton <marshbarton[ at ]wowway.com> 12/30/2008 12:49:15 AM
You're welcome.

The reason I thought that might be the case is because of
all the time I wasted learning this lesson the hard way ;-)
--
Marsh
MVP [MS Access]


kateri4482 wrote:
[Quoted Text]
>That is exactly the case. When I originally set up the table I had a field
>called "Date" until I realized that is not a good idea, so I created a new
>field but forgot to delete the old one. Thanks for the help!
>
>"Marshall Barton" wrote:
>
>> kateri4482 wrote:
>>
>> >I have the following code running from a command button, and it ignores the
>> >section after the "&" sign in the strTableName statement, so it just gives me
>> >a Table called tblBackupEnhancedCodes without the date. I can't figure out
>> >what I am doing wrong. I want to run this periodically and create a backup
>> >of a table but add the current date to the end of it.
>> >
>> >Dim strTableName As String, strSQL As String
>> >
>> >strTableName = "tblBaclupEnhancedCodes" & Format(Date, "ddmmmmyy")
>> >
>> >strSQL = "Select tblEnhancedCodes.* Into " & strTableName & " From
>> >tblEnhancedCodes;"
>>
>>
>> You probably have a text box named Date and its value is
>> Null.
>>
>> If so, it's just another reminder not to use reserved words
>> when you make up names.

Re: Code not working correctly
Dymondjack 12/31/2008 4:36:01 PM
Lookup Reddicks Naming Conventions for guidelines on how to name things in
vba... thats where I got my foundation from and (as far as I know) its
basically the standard.

I don't have any links handy but its easily googlable.

"kateri4482" wrote:

[Quoted Text]
> That is exactly the case. When I originally set up the table I had a field
> called "Date" until I realized that is not a good idea, so I created a new
> field but forgot to delete the old one. Thanks for the help!
>
> "Marshall Barton" wrote:
>
> > kateri4482 wrote:
> >
> > >I have the following code running from a command button, and it ignores the
> > >section after the "&" sign in the strTableName statement, so it just gives me
> > >a Table called tblBackupEnhancedCodes without the date. I can't figure out
> > >what I am doing wrong. I want to run this periodically and create a backup
> > >of a table but add the current date to the end of it.
> > >
> > >Dim strTableName As String, strSQL As String
> > >
> > >strTableName = "tblBaclupEnhancedCodes" & Format(Date, "ddmmmmyy")
> > >
> > >strSQL = "Select tblEnhancedCodes.* Into " & strTableName & " From
> > >tblEnhancedCodes;"
> >
> >
> > You probably have a text box named Date and its value is
> > Null.
> >
> > If so, it's just another reminder not to use reserved words
> > when you make up names.
> >
> > --
> > Marsh
> > MVP [MS Access]
> >

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net