返回驱动器名VBA从批处理文件访问 [英] Return Drive name to VBA in Access from batch file

查看:360
本文介绍了返回驱动器名VBA从批处理文件访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个映射下一个可用的免费的驱动器号到网络驱动器的批处理文件。我用它来映射SharePoint网站,然后使用文件共享文件夹在我的Access数据库。

I have a Batch file that maps the next available free drive letter to a network drive. I use this to map a sharepoint site and then use the documents in the shared folder in my Access database.

这是批处理文件(其中工程完美地映射netwrok)

this is the batch file (which works perfectly to map the netwrok)

@echo off
for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do CD %%a: 1>> nul 2>&1 & if errorlevel 1 set freedrive=%%a:
echo %freedrive%
pause
Net Use %freedrive% "http://XYZ/" 
pause

我把这个批处理文件从一种形式,访问VBA壳。因此,驱动器映射后,我想知道什么是分配的盘符,这样我可以运行我的MACRO它们可以从数据库链接,这个新映射(他的信,我不知道)表开车到当前的工作访问文件。 我不知道如何从一个批处理文件返回变量为VBA code,然后用它为我的其他工作。

I call this batch file as a shell from a form in Access VBA. So after the drive is mapped, I want to know what was the letter assigned so that I can run my MACRO which will link the tables from the databases on this newly mapped (whose letter I don't know) drive to the current operating Access file. I don't know how to return variables from a Batch file to a vba code and then use it for my other work.

EXTRA:我也想在最后删除的映射驱动器,当用户完成查询或编辑表格。此,当用户决定退出访问一般会发生。我可以写这另一个批处理文件,但我需要知道哪个驱动器盘符是为了删除使用!

EXTRA: I would also like to delete the mapped drive at the end when the user has finished querying or editing the tables. This would generally happen when the user decides to exit Access. I could write another batch file for this but I need to know which drive letter was used in order to delete it!

所有帮助是非常AP preciated!

All help is highly appreciated!

编辑: 我完全权衡与该链接所选择的答案提供的API调用批处理文件。整个事情是正确的综合接入和工作就像一个魅力! 和批处理文件code是不是我的。从我得到了它这里

I completely traded off the batch file with API calls for which the link is provided in the selected answer. The whole thing was integrated right in access and worked like a charm! and the batch file code is not mine. I got it from here

推荐答案

询问系统当前驱动器的列表。迭代信直到一个未出现在列表中。

Ask the system for a list of current drives. iterate letters until one does not appear in the list.

传递作为参数传递给该批处理文件。

Pass that as an argument to the batch file.

另外,您也可以替换 NET USE 与调用API; http://support.microsoft.com/kb/173011

Alternatively you can also replace the net use with calls to the API; http://support.microsoft.com/kb/173011

Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Function GetNextFreeDriveLetter() As String
    Dim buff As String, temp As Long
    buff = Space$(255)
    temp = GetLogicalDriveStrings(255, buff)
    If temp > 0 Then
        buff = vbNullChar & Left$(buff, temp)
        For temp = 67 To 90 'ascii C-Z
            If InStr(buff, vbNullChar & Chr$(temp) & ":\") = 0 Then
                GetNextFreeDriveLetter = Chr$(temp) & ":"
                Exit Function
            End If
        Next
    End If
End Function

这篇关于返回驱动器名VBA从批处理文件访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆