Visual Basic 6 issue 
Author Message
 Visual Basic 6 issue

I'm working on a simple database project for homework.  The database is to
be written in Visual Basic, and utilizes an Accel database file (*.mdb).  In
one subprocedure, I am attempting to use the FileCopy statement to copy the
values in template.mdb to newfile.mdb.
Here is the code I have so far:
                                      -----------------
Dim SourceFile, DestinationFile '<--DECLARING VARIABLES FOR FILECOPY

'USING COMMON DIALOG FOR FILENAME ENTRY
dlgCommon.Filter = "Access Database Files (*.mdb)|*.mdb|All Files (*.*)|*.*"
dlgCommon.DialogTitle = "File New Database"
dlgCommon.ShowSave 'displays the Save dialog box.

'Verifies a filename has been entered.
If dlgCommon.FileName = "" Then
    Exit Sub
    Else
    'Create the new filename 'CREATES THE NEW FILE IN THE SPECIFIED DIR.
    gstrFileName = dlgCommon.FileName
    Open gstrFileName For Output As #1
    Write #1, gstrFileName
    Close #1
End If

'FileCopy the carminder template to the new database file.
SourceFile = App.Path & "\carminder_template.mdp"
DestinationFile = gstrFileName
FileCopy SourceFile, DestinationFile '<--THIS IS WHERE IT BREAKS FOR ME.
                                      -----------------
As I mentioned, the code breaks at the "FileCopy SourceFile,
DestinationFile" line.  The error message is "File Not Found."
I checked the values of SourceFile & DestinationFile by displaying msgboxes.
The values are:
SourceFile = C:\My Documents\vb project\template.mdb
DestinationFile = C:\My Documents\vb project\newfile.mdb

For the life of me I can't figure out what I'm doing wrong here.  If anyone
has any serious suggestions, please help me out.  No sarcastic posts please.

Jedispy



Tue, 13 Dec 2005 14:09:19 GMT  
 Visual Basic 6 issue
Either there is some more code in between you setting the SourceFile
variable, or you have incorrectly explained what is happening.

On one line you set:

 SourceFile = App.Path & "\carminder_template.mdp"

Then a couple of lines later you say it stops and SourceFile is equal to
"C:\My Documents\vb project\template.mdb"

Recheck what you are doing, as this seems to be a case of simple oversight
of some sort.

Mauro


Quote:
> I'm working on a simple database project for homework.  The database is to
> be written in Visual Basic, and utilizes an Accel database file (*.mdb).
In
> one subprocedure, I am attempting to use the FileCopy statement to copy
the
> values in template.mdb to newfile.mdb.
> Here is the code I have so far:
>                                       -----------------
> Dim SourceFile, DestinationFile '<--DECLARING VARIABLES FOR FILECOPY

> 'USING COMMON DIALOG FOR FILENAME ENTRY
> dlgCommon.Filter = "Access Database Files (*.mdb)|*.mdb|All Files
(*.*)|*.*"
> dlgCommon.DialogTitle = "File New Database"
> dlgCommon.ShowSave 'displays the Save dialog box.

> 'Verifies a filename has been entered.
> If dlgCommon.FileName = "" Then
>     Exit Sub
>     Else
>     'Create the new filename 'CREATES THE NEW FILE IN THE SPECIFIED DIR.
>     gstrFileName = dlgCommon.FileName
>     Open gstrFileName For Output As #1
>     Write #1, gstrFileName
>     Close #1
> End If

> 'FileCopy the carminder template to the new database file.
> SourceFile = App.Path & "\carminder_template.mdp"
> DestinationFile = gstrFileName
> FileCopy SourceFile, DestinationFile '<--THIS IS WHERE IT BREAKS FOR ME.
>                                       -----------------
> As I mentioned, the code breaks at the "FileCopy SourceFile,
> DestinationFile" line.  The error message is "File Not Found."
> I checked the values of SourceFile & DestinationFile by displaying
msgboxes.
> The values are:
> SourceFile = C:\My Documents\vb project\template.mdb
> DestinationFile = C:\My Documents\vb project\newfile.mdb

> For the life of me I can't figure out what I'm doing wrong here.  If
anyone
> has any serious suggestions, please help me out.  No sarcastic posts
please.

> Jedispy



Tue, 13 Dec 2005 14:16:50 GMT  
 Visual Basic 6 issue
LOL I realized the error of my ways.  And it was so simple.
The error is in the line SourceFile = App.Path & "\carminder_template.mdp"

Access Database files are .mdB...not .mdP

That is the problem.  Thanks anyway.  Have a nice day.

Jedispy


Quote:
> Either there is some more code in between you setting the SourceFile
> variable, or you have incorrectly explained what is happening.

> On one line you set:

>  SourceFile = App.Path & "\carminder_template.mdp"

> Then a couple of lines later you say it stops and SourceFile is equal to
> "C:\My Documents\vb project\template.mdb"

> Recheck what you are doing, as this seems to be a case of simple oversight
> of some sort.

> Mauro



> > I'm working on a simple database project for homework.  The database is
to
> > be written in Visual Basic, and utilizes an Accel database file (*.mdb).
> In
> > one subprocedure, I am attempting to use the FileCopy statement to copy
> the
> > values in template.mdb to newfile.mdb.
> > Here is the code I have so far:
> >                                       -----------------
> > Dim SourceFile, DestinationFile '<--DECLARING VARIABLES FOR FILECOPY

> > 'USING COMMON DIALOG FOR FILENAME ENTRY
> > dlgCommon.Filter = "Access Database Files (*.mdb)|*.mdb|All Files
> (*.*)|*.*"
> > dlgCommon.DialogTitle = "File New Database"
> > dlgCommon.ShowSave 'displays the Save dialog box.

> > 'Verifies a filename has been entered.
> > If dlgCommon.FileName = "" Then
> >     Exit Sub
> >     Else
> >     'Create the new filename 'CREATES THE NEW FILE IN THE SPECIFIED DIR.
> >     gstrFileName = dlgCommon.FileName
> >     Open gstrFileName For Output As #1
> >     Write #1, gstrFileName
> >     Close #1
> > End If

> > 'FileCopy the carminder template to the new database file.
> > SourceFile = App.Path & "\carminder_template.mdp"
> > DestinationFile = gstrFileName
> > FileCopy SourceFile, DestinationFile '<--THIS IS WHERE IT BREAKS FOR ME.
> >                                       -----------------
> > As I mentioned, the code breaks at the "FileCopy SourceFile,
> > DestinationFile" line.  The error message is "File Not Found."
> > I checked the values of SourceFile & DestinationFile by displaying
> msgboxes.
> > The values are:
> > SourceFile = C:\My Documents\vb project\template.mdb
> > DestinationFile = C:\My Documents\vb project\newfile.mdb

> > For the life of me I can't figure out what I'm doing wrong here.  If
> anyone
> > has any serious suggestions, please help me out.  No sarcastic posts
> please.

> > Jedispy



Tue, 13 Dec 2005 14:39:52 GMT  
 Visual Basic 6 issue

Quote:
>                                       -----------------
> Dim SourceFile, DestinationFile '<--DECLARING VARIABLES FOR FILECOPY

You should declare these as strings not variants.
Where do you declare gstrFileName? (You'll lose marks if it's declared
globally)

Quote:

> 'USING COMMON DIALOG FOR FILENAME ENTRY
> dlgCommon.Filter = "Access Database Files (*.mdb)|*.mdb|All Files
(*.*)|*.*"
> dlgCommon.DialogTitle = "File New Database"
> dlgCommon.ShowSave 'displays the Save dialog box.

> 'Verifies a filename has been entered.
> If dlgCommon.FileName = "" Then
>     Exit Sub
>     Else

Poor structure. If you exit the sub there's no point in using the Else (just
use an End If). But better is to do the work if you have a valid filename:

If len(dlg.FileName) > 0 then
    :
End if

Quote:
>     'Create the new filename 'CREATES THE NEW FILE IN THE SPECIFIED DIR.
>     gstrFileName = dlgCommon.FileName
>     Open gstrFileName For Output As #1
>     Write #1, gstrFileName
>     Close #1

This is pointless. You're creating a text file and writing the name of the
file into it.

Quote:
> End If

> 'FileCopy the carminder template to the new database file.
> SourceFile = App.Path & "\carminder_template.mdp"
> DestinationFile = gstrFileName

Why introduce a new variable? What's wrong with gstrFileName.

Quote:
> FileCopy SourceFile, DestinationFile '<--THIS IS WHERE IT BREAKS FOR ME.
>                                       -----------------
> As I mentioned, the code breaks at the "FileCopy SourceFile,
> DestinationFile" line.  The error message is "File Not Found."
> I checked the values of SourceFile & DestinationFile by displaying
msgboxes.
> The values are:
> SourceFile = C:\My Documents\vb project\template.mdb

What happened to carminder_template.mdb ?

Quote:
> DestinationFile = C:\My Documents\vb project\newfile.mdb

> For the life of me I can't figure out what I'm doing wrong here.  If
anyone
> has any serious suggestions, please help me out.  No sarcastic posts
please.

> Jedispy



Tue, 13 Dec 2005 15:13:24 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Microsoft Word with Visual Basics 6.0 Issue

2. Visual Basic 6 issue

3. Oracle visual basic performance issue.

4. visual basic implementation issues

5. REQ - Visual Basic Magazine Issue 3

6. Visual Basic 6 issue

7. Visual Basic 6 issue

8. Visual Basic 5.0 Downward Compatibilty Issues

9. Visual Basic bugs (exsqueeze me, "issues")

10. Visual Basic 5.0 Downward Compatibilty Issues

11. Visual Basic Programmers Journal - May Issue

12. Some IIS setup issues running Visual Studio 6 / VB6 (very basic question, apologies)

 

 
Powered by phpBB® Forum Software