Selecting Drive to export/import data

R

Randy

Access 2000. I have 10 laptops with an identical db. I'm trying to export
and import files via Flashstick from the laptops to my main db. I have this
code to export files to my flashstick. The prolem is that the drive the
flashstick is on is not always "F", it varys from computor to computor.How
can I check which drive the flashstick is on prior to exporting the files?
Heres my code in the macro. ="F:\" &
[Forms]![ExportToFlashStick]![FileName5] & ".xls"

Here's whatI have in a cmd button on my form to import.

Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" & Me.List3,
True, ""
End Sub
 
R

Randy

Iv'e copied the code to a module. Where do I go from here? How do I run
the module?..
Douglas J. Steele said:
Take a look at http://www.mvps.org/access/api/api0003.htm at "The Access
Web"

It should show up as "Removable Drive"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
Access 2000. I have 10 laptops with an identical db. I'm trying to
export and import files via Flashstick from the laptops to my main db. I
have this code to export files to my flashstick. The prolem is that the
drive the flashstick is on is not always "F", it varys from computor to
computor.How can I check which drive the flashstick is on prior to
exporting the files? Heres my code in the macro. ="F:\" &
[Forms]![ExportToFlashStick]![FileName5] & ".xls"

Here's whatI have in a cmd button on my form to import.

Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" & Me.List3,
True, ""
End Sub
 
D

Douglas J. Steele

Open the Debug Window (Ctrl-G), type sListAllDrives and hit enter. You
should get a list of all of your drives. For instance, here's what I get if
I don't have a thumbdrive attached:

sListAllDrives
Local drive : C:\
Local drive : D:\
CD Rom drive : Z:\

And when I do have a thumbdrive:

sListAllDrives
Local drive : C:\
Local drive : D:\
Removable drive : F:\
CD Rom drive : Z:\

Now, you could write A function that loops through and returns the first
Removable Drive it finds, along the lines of

Function FirstRemovable() As Variant
Dim strAllDrives As String
Dim strTmp As String

FirstRemovable = Null
strAllDrives = fGetDrives
If strAllDrives <> "" Then
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives, vbNullChar) -
1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives,
vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media":
FirstRemovable = strTmp
Exit Do
End Select
Loop While strAllDrives <> ""
End If
End Function

However, recognize that if they've got more than one removable drive
attached, that may not result in what you want.





--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
Iv'e copied the code to a module. Where do I go from here? How do I run
the module?..
Douglas J. Steele said:
Take a look at http://www.mvps.org/access/api/api0003.htm at "The Access
Web"

It should show up as "Removable Drive"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
Access 2000. I have 10 laptops with an identical db. I'm trying to
export and import files via Flashstick from the laptops to my main db. I
have this code to export files to my flashstick. The prolem is that the
drive the flashstick is on is not always "F", it varys from computor to
computor.How can I check which drive the flashstick is on prior to
exporting the files? Heres my code in the macro. ="F:\" &
[Forms]![ExportToFlashStick]![FileName5] & ".xls"

Here's whatI have in a cmd button on my form to import.

Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" & Me.List3,
True, ""
End Sub
 
R

Randy

Thank you, I'll give it a try. Thanks for your response...Randy
Douglas J. Steele said:
Open the Debug Window (Ctrl-G), type sListAllDrives and hit enter. You
should get a list of all of your drives. For instance, here's what I get
if I don't have a thumbdrive attached:

sListAllDrives
Local drive : C:\
Local drive : D:\
CD Rom drive : Z:\

And when I do have a thumbdrive:

sListAllDrives
Local drive : C:\
Local drive : D:\
Removable drive : F:\
CD Rom drive : Z:\

Now, you could write A function that loops through and returns the first
Removable Drive it finds, along the lines of

Function FirstRemovable() As Variant
Dim strAllDrives As String
Dim strTmp As String

FirstRemovable = Null
strAllDrives = fGetDrives
If strAllDrives <> "" Then
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives,
vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives,
vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media":
FirstRemovable = strTmp
Exit Do
End Select
Loop While strAllDrives <> ""
End If
End Function

However, recognize that if they've got more than one removable drive
attached, that may not result in what you want.





--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
Iv'e copied the code to a module. Where do I go from here? How do I run
the module?..
Douglas J. Steele said:
Take a look at http://www.mvps.org/access/api/api0003.htm at "The Access
Web"

It should show up as "Removable Drive"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Access 2000. I have 10 laptops with an identical db. I'm trying to
export and import files via Flashstick from the laptops to my main db.
I have this code to export files to my flashstick. The prolem is that
the drive the flashstick is on is not always "F", it varys from
computor to computor.How can I check which drive the flashstick is on
prior to exporting the files? Heres my code in the macro. ="F:\" &
[Forms]![ExportToFlashStick]![FileName5] & ".xls"

Here's whatI have in a cmd button on my form to import.

Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" &
Me.List3, True, ""
End Sub
 
R

Randy

I couldnt get it to work. I have a form where I enter the file name to be
exported, the beginning date and ending date. I have a cmd button to run a
macro that transfers data to the f drive (Flashstick) but not all computors
has the F drive as the reoveable drive. I need a way that when you click
the cmd button, something asks for the drive location of the flashstick and
once I click on the correct location the file is transferred. Thank you...
Randy said:
Thank you, I'll give it a try. Thanks for your response...Randy
Douglas J. Steele said:
Open the Debug Window (Ctrl-G), type sListAllDrives and hit enter. You
should get a list of all of your drives. For instance, here's what I get
if I don't have a thumbdrive attached:

sListAllDrives
Local drive : C:\
Local drive : D:\
CD Rom drive : Z:\

And when I do have a thumbdrive:

sListAllDrives
Local drive : C:\
Local drive : D:\
Removable drive : F:\
CD Rom drive : Z:\

Now, you could write A function that loops through and returns the first
Removable Drive it finds, along the lines of

Function FirstRemovable() As Variant
Dim strAllDrives As String
Dim strTmp As String

FirstRemovable = Null
strAllDrives = fGetDrives
If strAllDrives <> "" Then
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives,
vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives,
vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media":
FirstRemovable = strTmp
Exit Do
End Select
Loop While strAllDrives <> ""
End If
End Function

However, recognize that if they've got more than one removable drive
attached, that may not result in what you want.





--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
Iv'e copied the code to a module. Where do I go from here? How do I
run the module?..
Take a look at http://www.mvps.org/access/api/api0003.htm at "The
Access Web"

It should show up as "Removable Drive"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Access 2000. I have 10 laptops with an identical db. I'm trying to
export and import files via Flashstick from the laptops to my main db.
I have this code to export files to my flashstick. The prolem is that
the drive the flashstick is on is not always "F", it varys from
computor to computor.How can I check which drive the flashstick is on
prior to exporting the files? Heres my code in the macro. ="F:\" &
[Forms]![ExportToFlashStick]![FileName5] & ".xls"

Here's whatI have in a cmd button on my form to import.

Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" &
Me.List3, True, ""
End Sub
 
D

Douglas J. Steele

Sorry, but "couldnt get it to work" doesn't give much to go on.

Do you get an error? If so, what is it? If there's no error, what result do
you get, and what should you get?

Including the code you're using would help a lot too...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
I couldnt get it to work. I have a form where I enter the file name to be
exported, the beginning date and ending date. I have a cmd button to run a
macro that transfers data to the f drive (Flashstick) but not all computors
has the F drive as the reoveable drive. I need a way that when you click
the cmd button, something asks for the drive location of the flashstick and
once I click on the correct location the file is transferred. Thank you...
Randy said:
Thank you, I'll give it a try. Thanks for your response...Randy
Douglas J. Steele said:
Open the Debug Window (Ctrl-G), type sListAllDrives and hit enter. You
should get a list of all of your drives. For instance, here's what I get
if I don't have a thumbdrive attached:

sListAllDrives
Local drive : C:\
Local drive : D:\
CD Rom drive : Z:\

And when I do have a thumbdrive:

sListAllDrives
Local drive : C:\
Local drive : D:\
Removable drive : F:\
CD Rom drive : Z:\

Now, you could write A function that loops through and returns the first
Removable Drive it finds, along the lines of

Function FirstRemovable() As Variant
Dim strAllDrives As String
Dim strTmp As String

FirstRemovable = Null
strAllDrives = fGetDrives
If strAllDrives <> "" Then
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives,
vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives,
vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media":
FirstRemovable = strTmp
Exit Do
End Select
Loop While strAllDrives <> ""
End If
End Function

However, recognize that if they've got more than one removable drive
attached, that may not result in what you want.





--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Iv'e copied the code to a module. Where do I go from here? How do I
run the module?..
message Take a look at http://www.mvps.org/access/api/api0003.htm at "The
Access Web"

It should show up as "Removable Drive"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Access 2000. I have 10 laptops with an identical db. I'm trying to
export and import files via Flashstick from the laptops to my main
db. I have this code to export files to my flashstick. The prolem is
that the drive the flashstick is on is not always "F", it varys from
computor to computor.How can I check which drive the flashstick is on
prior to exporting the files? Heres my code in the macro. ="F:\" &
[Forms]![ExportToFlashStick]![FileName5] & ".xls"

Here's whatI have in a cmd button on my form to import.

Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" &
Me.List3, True, ""
End Sub
 
R

Randy

Heres my code in my macro, file Name to transfer data:
="F:\" & [Forms]![ExportToFlashStick]![FileName5] & ".xls" Heres my code
to imports data via cmd button on my form:
Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" & Me.List3,
True, ""
End Sub

Like I said, the directory is not always "F"
Douglas J. Steele said:
Sorry, but "couldnt get it to work" doesn't give much to go on.

Do you get an error? If so, what is it? If there's no error, what result
do you get, and what should you get?

Including the code you're using would help a lot too...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
I couldnt get it to work. I have a form where I enter the file name to be
exported, the beginning date and ending date. I have a cmd button to run
a macro that transfers data to the f drive (Flashstick) but not all
computors has the F drive as the reoveable drive. I need a way that when
you click the cmd button, something asks for the drive location of the
flashstick and once I click on the correct location the file is
transferred. Thank you...
Randy said:
Thank you, I'll give it a try. Thanks for your response...Randy
Open the Debug Window (Ctrl-G), type sListAllDrives and hit enter. You
should get a list of all of your drives. For instance, here's what I
get if I don't have a thumbdrive attached:

sListAllDrives
Local drive : C:\
Local drive : D:\
CD Rom drive : Z:\

And when I do have a thumbdrive:

sListAllDrives
Local drive : C:\
Local drive : D:\
Removable drive : F:\
CD Rom drive : Z:\

Now, you could write A function that loops through and returns the
first Removable Drive it finds, along the lines of

Function FirstRemovable() As Variant
Dim strAllDrives As String
Dim strTmp As String

FirstRemovable = Null
strAllDrives = fGetDrives
If strAllDrives <> "" Then
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives,
vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives,
vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media":
FirstRemovable = strTmp
Exit Do
End Select
Loop While strAllDrives <> ""
End If
End Function

However, recognize that if they've got more than one removable drive
attached, that may not result in what you want.





--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Iv'e copied the code to a module. Where do I go from here? How do I
run the module?..
message Take a look at http://www.mvps.org/access/api/api0003.htm at "The
Access Web"

It should show up as "Removable Drive"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Access 2000. I have 10 laptops with an identical db. I'm trying to
export and import files via Flashstick from the laptops to my main
db. I have this code to export files to my flashstick. The prolem
is that the drive the flashstick is on is not always "F", it varys
from computor to computor.How can I check which drive the flashstick
is on prior to exporting the files? Heres my code in the macro.
="F:\" & [Forms]![ExportToFlashStick]![FileName5] & ".xls"

Here's whatI have in a cmd button on my form to import.

Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" &
Me.List3, True, ""
End Sub
 
D

Douglas J. Steele

Looks as though you didn't make any changes to your original code, as though
you didn't read the suggestion I gave you at all!

You say you copied the code from http://www.mvps.org/access/api/api0003.htm
into a module. Did you also copy the additional code for the
FirstRemovable() function I gave you?

Assuming you did, change your code to:

Private Sub ImportFlashStick_Click()

DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", FirstRemovable() &
Me.List3, True, ""

End Sub

As I said before, you may run into problems with this if a particular user
has more than one removable drive installed.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
Heres my code in my macro, file Name to transfer data:
="F:\" & [Forms]![ExportToFlashStick]![FileName5] & ".xls" Heres my code
to imports data via cmd button on my form:
Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" & Me.List3,
True, ""
End Sub

Like I said, the directory is not always "F"
Douglas J. Steele said:
Sorry, but "couldnt get it to work" doesn't give much to go on.

Do you get an error? If so, what is it? If there's no error, what result
do you get, and what should you get?

Including the code you're using would help a lot too...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
I couldnt get it to work. I have a form where I enter the file name to
be exported, the beginning date and ending date. I have a cmd button to
run a macro that transfers data to the f drive (Flashstick) but not all
computors has the F drive as the reoveable drive. I need a way that when
you click the cmd button, something asks for the drive location of the
flashstick and once I click on the correct location the file is
transferred. Thank you...
Thank you, I'll give it a try. Thanks for your response...Randy
message Open the Debug Window (Ctrl-G), type sListAllDrives and hit enter. You
should get a list of all of your drives. For instance, here's what I
get if I don't have a thumbdrive attached:

sListAllDrives
Local drive : C:\
Local drive : D:\
CD Rom drive : Z:\

And when I do have a thumbdrive:

sListAllDrives
Local drive : C:\
Local drive : D:\
Removable drive : F:\
CD Rom drive : Z:\

Now, you could write A function that loops through and returns the
first Removable Drive it finds, along the lines of

Function FirstRemovable() As Variant
Dim strAllDrives As String
Dim strTmp As String

FirstRemovable = Null
strAllDrives = fGetDrives
If strAllDrives <> "" Then
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives,
vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives,
vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media":
FirstRemovable = strTmp
Exit Do
End Select
Loop While strAllDrives <> ""
End If
End Function

However, recognize that if they've got more than one removable drive
attached, that may not result in what you want.





--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Iv'e copied the code to a module. Where do I go from here? How do I
run the module?..
message Take a look at http://www.mvps.org/access/api/api0003.htm at "The
Access Web"

It should show up as "Removable Drive"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Access 2000. I have 10 laptops with an identical db. I'm trying
to export and import files via Flashstick from the laptops to my
main db. I have this code to export files to my flashstick. The
prolem is that the drive the flashstick is on is not always "F", it
varys from computor to computor.How can I check which drive the
flashstick is on prior to exporting the files? Heres my code in the
macro. ="F:\" & [Forms]![ExportToFlashStick]![FileName5] & ".xls"

Here's whatI have in a cmd button on my form to import.

Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" &
Me.List3, True, ""
End Sub
 
R

Randy

I have followed your suggestions to a T. I did copy the module and your
code. When I click my cmd button I get "Complie error, sub or function not
defined, when debugged the "Function First Removable" is highlighted at
"Select Case fdrive type" I appreciate your help...Randy
Douglas J. Steele said:
Looks as though you didn't make any changes to your original code, as
though you didn't read the suggestion I gave you at all!

You say you copied the code from
http://www.mvps.org/access/api/api0003.htm into a module. Did you also
copy the additional code for the FirstRemovable() function I gave you?

Assuming you did, change your code to:

Private Sub ImportFlashStick_Click()

DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", FirstRemovable() &
Me.List3, True, ""

End Sub

As I said before, you may run into problems with this if a particular user
has more than one removable drive installed.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
Heres my code in my macro, file Name to transfer data:
="F:\" & [Forms]![ExportToFlashStick]![FileName5] & ".xls" Heres my
code to imports data via cmd button on my form:
Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" & Me.List3,
True, ""
End Sub

Like I said, the directory is not always "F"
Douglas J. Steele said:
Sorry, but "couldnt get it to work" doesn't give much to go on.

Do you get an error? If so, what is it? If there's no error, what result
do you get, and what should you get?

Including the code you're using would help a lot too...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I couldnt get it to work. I have a form where I enter the file name to
be exported, the beginning date and ending date. I have a cmd button to
run a macro that transfers data to the f drive (Flashstick) but not all
computors has the F drive as the reoveable drive. I need a way that
when you click the cmd button, something asks for the drive location of
the flashstick and once I click on the correct location the file is
transferred. Thank you...
Thank you, I'll give it a try. Thanks for your response...Randy
message Open the Debug Window (Ctrl-G), type sListAllDrives and hit enter.
You should get a list of all of your drives. For instance, here's
what I get if I don't have a thumbdrive attached:

sListAllDrives
Local drive : C:\
Local drive : D:\
CD Rom drive : Z:\

And when I do have a thumbdrive:

sListAllDrives
Local drive : C:\
Local drive : D:\
Removable drive : F:\
CD Rom drive : Z:\

Now, you could write A function that loops through and returns the
first Removable Drive it finds, along the lines of

Function FirstRemovable() As Variant
Dim strAllDrives As String
Dim strTmp As String

FirstRemovable = Null
strAllDrives = fGetDrives
If strAllDrives <> "" Then
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives,
vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives,
vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media":
FirstRemovable = strTmp
Exit Do
End Select
Loop While strAllDrives <> ""
End If
End Function

However, recognize that if they've got more than one removable drive
attached, that may not result in what you want.





--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Iv'e copied the code to a module. Where do I go from here? How do
I run the module?..
message Take a look at http://www.mvps.org/access/api/api0003.htm at "The
Access Web"

It should show up as "Removable Drive"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Access 2000. I have 10 laptops with an identical db. I'm trying
to export and import files via Flashstick from the laptops to my
main db. I have this code to export files to my flashstick. The
prolem is that the drive the flashstick is on is not always "F",
it varys from computor to computor.How can I check which drive the
flashstick is on prior to exporting the files? Heres my code in
the macro. ="F:\" & [Forms]![ExportToFlashStick]![FileName5] &
".xls"

Here's whatI have in a cmd button on my form to import.

Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" &
Me.List3, True, ""
End Sub
 
D

Douglas J. Steele

Where did you put the code for FirstRemovable? It needs to be in the same
module as the code from "The Access Web", or else you have to go into the
module containing the code from the web and change

Private Function fDriveType(strDriveName As String) As String

to

Public Function fDriveType(strDriveName As String) As String


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
I have followed your suggestions to a T. I did copy the module and your
code. When I click my cmd button I get "Complie error, sub or function not
defined, when debugged the "Function First Removable" is highlighted at
"Select Case fdrive type" I appreciate your help...Randy
Douglas J. Steele said:
Looks as though you didn't make any changes to your original code, as
though you didn't read the suggestion I gave you at all!

You say you copied the code from
http://www.mvps.org/access/api/api0003.htm into a module. Did you also
copy the additional code for the FirstRemovable() function I gave you?

Assuming you did, change your code to:

Private Sub ImportFlashStick_Click()

DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", FirstRemovable()
& Me.List3, True, ""

End Sub

As I said before, you may run into problems with this if a particular
user has more than one removable drive installed.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
Heres my code in my macro, file Name to transfer data:
="F:\" & [Forms]![ExportToFlashStick]![FileName5] & ".xls" Heres my
code to imports data via cmd button on my form:
Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" & Me.List3,
True, ""
End Sub

Like I said, the directory is not always "F"
Sorry, but "couldnt get it to work" doesn't give much to go on.

Do you get an error? If so, what is it? If there's no error, what
result do you get, and what should you get?

Including the code you're using would help a lot too...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I couldnt get it to work. I have a form where I enter the file name to
be exported, the beginning date and ending date. I have a cmd button
to run a macro that transfers data to the f drive (Flashstick) but not
all computors has the F drive as the reoveable drive. I need a way
that when you click the cmd button, something asks for the drive
location of the flashstick and once I click on the correct location the
file is transferred. Thank you...
Thank you, I'll give it a try. Thanks for your response...Randy
message Open the Debug Window (Ctrl-G), type sListAllDrives and hit enter.
You should get a list of all of your drives. For instance, here's
what I get if I don't have a thumbdrive attached:

sListAllDrives
Local drive : C:\
Local drive : D:\
CD Rom drive : Z:\

And when I do have a thumbdrive:

sListAllDrives
Local drive : C:\
Local drive : D:\
Removable drive : F:\
CD Rom drive : Z:\

Now, you could write A function that loops through and returns the
first Removable Drive it finds, along the lines of

Function FirstRemovable() As Variant
Dim strAllDrives As String
Dim strTmp As String

FirstRemovable = Null
strAllDrives = fGetDrives
If strAllDrives <> "" Then
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives,
vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives,
vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media":
FirstRemovable = strTmp
Exit Do
End Select
Loop While strAllDrives <> ""
End If
End Function

However, recognize that if they've got more than one removable drive
attached, that may not result in what you want.





--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Iv'e copied the code to a module. Where do I go from here? How do
I run the module?..
message Take a look at http://www.mvps.org/access/api/api0003.htm at "The
Access Web"

It should show up as "Removable Drive"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Access 2000. I have 10 laptops with an identical db. I'm trying
to export and import files via Flashstick from the laptops to my
main db. I have this code to export files to my flashstick. The
prolem is that the drive the flashstick is on is not always "F",
it varys from computor to computor.How can I check which drive
the flashstick is on prior to exporting the files? Heres my code
in the macro. ="F:\" & [Forms]![ExportToFlashStick]![FileName5] &
".xls"

Here's whatI have in a cmd button on my form to import.

Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" &
Me.List3, True, ""
End Sub
 
R

Randy

Ok, I corrected the module. Now I get: "Runtime error 3031, The microsoft
datajet engine could not find the object A:\12345.xls, make sure the object
exists..." The flashstick drive on this computor is J. I do hear the
floppy drive working, searching for the file...Randy

Douglas J. Steele said:
Where did you put the code for FirstRemovable? It needs to be in the same
module as the code from "The Access Web", or else you have to go into the
module containing the code from the web and change

Private Function fDriveType(strDriveName As String) As String

to

Public Function fDriveType(strDriveName As String) As String


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
I have followed your suggestions to a T. I did copy the module and your
code. When I click my cmd button I get "Complie error, sub or function
not defined, when debugged the "Function First Removable" is highlighted
at "Select Case fdrive type" I appreciate your help...Randy
Douglas J. Steele said:
Looks as though you didn't make any changes to your original code, as
though you didn't read the suggestion I gave you at all!

You say you copied the code from
http://www.mvps.org/access/api/api0003.htm into a module. Did you also
copy the additional code for the FirstRemovable() function I gave you?

Assuming you did, change your code to:

Private Sub ImportFlashStick_Click()

DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", FirstRemovable()
& Me.List3, True, ""

End Sub

As I said before, you may run into problems with this if a particular
user has more than one removable drive installed.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Heres my code in my macro, file Name to transfer data:
="F:\" & [Forms]![ExportToFlashStick]![FileName5] & ".xls" Heres my
code to imports data via cmd button on my form:
Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" &
Me.List3, True, ""
End Sub

Like I said, the directory is not always "F"
message Sorry, but "couldnt get it to work" doesn't give much to go on.

Do you get an error? If so, what is it? If there's no error, what
result do you get, and what should you get?

Including the code you're using would help a lot too...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I couldnt get it to work. I have a form where I enter the file name
to be exported, the beginning date and ending date. I have a cmd
button to run a macro that transfers data to the f drive (Flashstick)
but not all computors has the F drive as the reoveable drive. I need
a way that when you click the cmd button, something asks for the drive
location of the flashstick and once I click on the correct location
the file is transferred. Thank you...
Thank you, I'll give it a try. Thanks for your response...Randy
message Open the Debug Window (Ctrl-G), type sListAllDrives and hit enter.
You should get a list of all of your drives. For instance, here's
what I get if I don't have a thumbdrive attached:

sListAllDrives
Local drive : C:\
Local drive : D:\
CD Rom drive : Z:\

And when I do have a thumbdrive:

sListAllDrives
Local drive : C:\
Local drive : D:\
Removable drive : F:\
CD Rom drive : Z:\

Now, you could write A function that loops through and returns the
first Removable Drive it finds, along the lines of

Function FirstRemovable() As Variant
Dim strAllDrives As String
Dim strTmp As String

FirstRemovable = Null
strAllDrives = fGetDrives
If strAllDrives <> "" Then
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives,
vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives,
vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media":
FirstRemovable = strTmp
Exit Do
End Select
Loop While strAllDrives <> ""
End If
End Function

However, recognize that if they've got more than one removable
drive attached, that may not result in what you want.





--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Iv'e copied the code to a module. Where do I go from here? How
do I run the module?..
message Take a look at http://www.mvps.org/access/api/api0003.htm at "The
Access Web"

It should show up as "Removable Drive"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Access 2000. I have 10 laptops with an identical db. I'm
trying to export and import files via Flashstick from the
laptops to my main db. I have this code to export files to my
flashstick. The prolem is that the drive the flashstick is on
is not always "F", it varys from computor to computor.How can I
check which drive the flashstick is on prior to exporting the
files? Heres my code in the macro. ="F:\" &
[Forms]![ExportToFlashStick]![FileName5] & ".xls"

Here's whatI have in a cmd button on my form to import.

Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" &
Me.List3, True, ""
End Sub
 
D

Douglas J. Steele

Make sure that FirstRemovable() is giving you the correct drive letter.

Try:

Dim strFile As String

strFile = FirstRemovable() & Me.List3
MsgBox strFile
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", strFile , True, ""


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
Ok, I corrected the module. Now I get: "Runtime error 3031, The microsoft
datajet engine could not find the object A:\12345.xls, make sure the
object exists..." The flashstick drive on this computor is J. I do hear
the floppy drive working, searching for the file...Randy

Douglas J. Steele said:
Where did you put the code for FirstRemovable? It needs to be in the same
module as the code from "The Access Web", or else you have to go into the
module containing the code from the web and change

Private Function fDriveType(strDriveName As String) As String

to

Public Function fDriveType(strDriveName As String) As String


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
I have followed your suggestions to a T. I did copy the module and your
code. When I click my cmd button I get "Complie error, sub or function
not defined, when debugged the "Function First Removable" is highlighted
at "Select Case fdrive type" I appreciate your help...Randy
Looks as though you didn't make any changes to your original code, as
though you didn't read the suggestion I gave you at all!

You say you copied the code from
http://www.mvps.org/access/api/api0003.htm into a module. Did you also
copy the additional code for the FirstRemovable() function I gave you?

Assuming you did, change your code to:

Private Sub ImportFlashStick_Click()

DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm",
FirstRemovable() & Me.List3, True, ""

End Sub

As I said before, you may run into problems with this if a particular
user has more than one removable drive installed.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Heres my code in my macro, file Name to transfer data:
="F:\" & [Forms]![ExportToFlashStick]![FileName5] & ".xls" Heres my
code to imports data via cmd button on my form:
Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" &
Me.List3, True, ""
End Sub

Like I said, the directory is not always "F"
message Sorry, but "couldnt get it to work" doesn't give much to go on.

Do you get an error? If so, what is it? If there's no error, what
result do you get, and what should you get?

Including the code you're using would help a lot too...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I couldnt get it to work. I have a form where I enter the file name
to be exported, the beginning date and ending date. I have a cmd
button to run a macro that transfers data to the f drive (Flashstick)
but not all computors has the F drive as the reoveable drive. I need
a way that when you click the cmd button, something asks for the
drive location of the flashstick and once I click on the correct
location the file is transferred. Thank you...
Thank you, I'll give it a try. Thanks for your response...Randy
message Open the Debug Window (Ctrl-G), type sListAllDrives and hit enter.
You should get a list of all of your drives. For instance, here's
what I get if I don't have a thumbdrive attached:

sListAllDrives
Local drive : C:\
Local drive : D:\
CD Rom drive : Z:\

And when I do have a thumbdrive:

sListAllDrives
Local drive : C:\
Local drive : D:\
Removable drive : F:\
CD Rom drive : Z:\

Now, you could write A function that loops through and returns the
first Removable Drive it finds, along the lines of

Function FirstRemovable() As Variant
Dim strAllDrives As String
Dim strTmp As String

FirstRemovable = Null
strAllDrives = fGetDrives
If strAllDrives <> "" Then
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives,
vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives,
vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media":
FirstRemovable = strTmp
Exit Do
End Select
Loop While strAllDrives <> ""
End If
End Function

However, recognize that if they've got more than one removable
drive attached, that may not result in what you want.





--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Iv'e copied the code to a module. Where do I go from here? How
do I run the module?..
message Take a look at http://www.mvps.org/access/api/api0003.htm at
"The Access Web"

It should show up as "Removable Drive"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Access 2000. I have 10 laptops with an identical db. I'm
trying to export and import files via Flashstick from the
laptops to my main db. I have this code to export files to my
flashstick. The prolem is that the drive the flashstick is on
is not always "F", it varys from computor to computor.How can I
check which drive the flashstick is on prior to exporting the
files? Heres my code in the macro. ="F:\" &
[Forms]![ExportToFlashStick]![FileName5] & ".xls"

Here's whatI have in a cmd button on my form to import.

Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" &
Me.List3, True, ""
End Sub
 
R

Randy

I appreciate your efforts, but none of this is working. I'll see if I can
find another aproach. Thanks again...Randy
Douglas J. Steele said:
Make sure that FirstRemovable() is giving you the correct drive letter.

Try:

Dim strFile As String

strFile = FirstRemovable() & Me.List3
MsgBox strFile
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", strFile , True,
""


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Randy said:
Ok, I corrected the module. Now I get: "Runtime error 3031, The
microsoft datajet engine could not find the object A:\12345.xls, make
sure the object exists..." The flashstick drive on this computor is J.
I do hear the floppy drive working, searching for the file...Randy

Douglas J. Steele said:
Where did you put the code for FirstRemovable? It needs to be in the
same module as the code from "The Access Web", or else you have to go
into the module containing the code from the web and change

Private Function fDriveType(strDriveName As String) As String

to

Public Function fDriveType(strDriveName As String) As String


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I have followed your suggestions to a T. I did copy the module and your
code. When I click my cmd button I get "Complie error, sub or function
not defined, when debugged the "Function First Removable" is highlighted
at "Select Case fdrive type" I appreciate your help...Randy
message Looks as though you didn't make any changes to your original code, as
though you didn't read the suggestion I gave you at all!

You say you copied the code from
http://www.mvps.org/access/api/api0003.htm into a module. Did you also
copy the additional code for the FirstRemovable() function I gave you?

Assuming you did, change your code to:

Private Sub ImportFlashStick_Click()

DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm",
FirstRemovable() & Me.List3, True, ""

End Sub

As I said before, you may run into problems with this if a particular
user has more than one removable drive installed.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Heres my code in my macro, file Name to transfer data:
="F:\" & [Forms]![ExportToFlashStick]![FileName5] & ".xls" Heres my
code to imports data via cmd button on my form:
Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" &
Me.List3, True, ""
End Sub

Like I said, the directory is not always "F"
message Sorry, but "couldnt get it to work" doesn't give much to go on.

Do you get an error? If so, what is it? If there's no error, what
result do you get, and what should you get?

Including the code you're using would help a lot too...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



I couldnt get it to work. I have a form where I enter the file name
to be exported, the beginning date and ending date. I have a cmd
button to run a macro that transfers data to the f drive
(Flashstick) but not all computors has the F drive as the reoveable
drive. I need a way that when you click the cmd button, something
asks for the drive location of the flashstick and once I click on
the correct location the file is transferred. Thank you...
Thank you, I'll give it a try. Thanks for your response...Randy
message Open the Debug Window (Ctrl-G), type sListAllDrives and hit
enter. You should get a list of all of your drives. For instance,
here's what I get if I don't have a thumbdrive attached:

sListAllDrives
Local drive : C:\
Local drive : D:\
CD Rom drive : Z:\

And when I do have a thumbdrive:

sListAllDrives
Local drive : C:\
Local drive : D:\
Removable drive : F:\
CD Rom drive : Z:\

Now, you could write A function that loops through and returns
the first Removable Drive it finds, along the lines of

Function FirstRemovable() As Variant
Dim strAllDrives As String
Dim strTmp As String

FirstRemovable = Null
strAllDrives = fGetDrives
If strAllDrives <> "" Then
Do
strTmp = Mid$(strAllDrives, 1, InStr(strAllDrives,
vbNullChar) - 1)
strAllDrives = Mid$(strAllDrives, InStr(strAllDrives,
vbNullChar) + 1)
Select Case fDriveType(strTmp)
Case "Removable Media":
FirstRemovable = strTmp
Exit Do
End Select
Loop While strAllDrives <> ""
End If
End Function

However, recognize that if they've got more than one removable
drive attached, that may not result in what you want.





--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Iv'e copied the code to a module. Where do I go from here? How
do I run the module?..
message Take a look at http://www.mvps.org/access/api/api0003.htm at
"The Access Web"

It should show up as "Removable Drive"

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Access 2000. I have 10 laptops with an identical db. I'm
trying to export and import files via Flashstick from the
laptops to my main db. I have this code to export files to my
flashstick. The prolem is that the drive the flashstick is on
is not always "F", it varys from computor to computor.How can
I check which drive the flashstick is on prior to exporting
the files? Heres my code in the macro. ="F:\" &
[Forms]![ExportToFlashStick]![FileName5] & ".xls"

Here's whatI have in a cmd button on my form to import.

Private Sub ImportFlashStick_Click()
DoCmd.TransferSpreadsheet acImport, 8, "AnalysisForm", "F:\" &
Me.List3, True, ""
End Sub
 
D

Douglas J. Steele

I don't understand. If strFile is pointing to the correct file, then the
TransferSpreadsheet should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top