Msaccess 2103运行时错误CreateObject [英] Msaccess 2103 runtime error CreateObject

查看:157
本文介绍了Msaccess 2103运行时错误CreateObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在完整版MsAccess 2010中正常运行的数据库。但是在运行时&#bsp; MsAccess 2013显示错误。

I have a database that works correctly in the full version of MsAccess 2010 . but in the runtime  MsAccess 2013 shows error.

............................ .................................................. .................................................. .........

.........................................................................................................................................

Dim NameTable,pathbd

Pathbd = DLookup(" [Dir_installl]"," tb_Config"," ; [Dir_install]")

NameTable =" tborcadoTemp"

Dim NameTable, pathbd
Pathbd = DLookup("[Dir_installl]", "tb_Config", "[Dir_install]")
NameTable = "tborcadoTemp"

设置objaccess = CreateObject(" Access.Application")

Set objaccess = CreateObject("Access.Application")

objaccess.NewCurrentDatabase pathbd& " tbrealizadoTemp.accdb"

objaccess.NewCurrentDatabase pathbd & "tbrealizadoTemp.accdb"

................................... .................................................. ..............................................

...................................................................................................................................

此代码创建一个accdb文件,然后将数据从一张表传输给他。

this code create a accdb file and then do the transfer of data from one sheet to him.

运行运行时不知道怎么做?

Running the runtime do not how to accomplish this?

谢谢

推荐答案

要在运行时运行它,您的代码需要处理错误。 objacess的声明也缺失了。 tablename和pathbd隐式声明为variant。但是在阅读代码时,它们必须是一个字符串。该路径还必须包含一个尾随的
路径分隔符。您还需要验证输入。例如

For running it in the runtime, your code needs error handling. Also the declaration for objacess is missing. And tablename and pathbd are implicitly declared as variant. But when reading the code, they must be a string. Also the path must include a trailing path delimiter. You also need to verify the input. E.g.

Public Sub ImportData

  On Local Error GoTo LocalError
  
  Dim AccessApplication As Access.Application
  Dim DatabasePath As String
  Dim FileName As String
  Dim TableName As String
  
 1  DatabasePath = Trim(DLookup("[Dir_installl]", "tb_Config", "[Dir_install]"))
 2  If (Len(DatabasePath) > 1) And (Right(DatabasePath, 1) <> = "\") Then
 3    DatabasePath = DatabasePath & "\"
 4  End If
   
 5  FileName = Forms![Frm_Import]![Local]
 6  If (Len(Dir(FileName)) = 0) Then
 7    MsgBox "File " & FileName & " does not exist."
 8    Exit Sub
 9  End If
 
10  TableName = "tborcadoTemp" 
     
11  Set AccessApplication = CreateObject("Access.Application")
12  AccessApplication.NewCurrentDatabase DatabasePath & "tbrealizadoTemp.accdb"
13  AccessApplication.DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, TableName, FileName, True
14  AccessApplication.Quit 
15  Set AccessApplication = Nothing
  
  Exit Sub

LocalError:
  MsgBox Err.Description & " at line " & Erl()
  On Local Error Resume Next
  AccessApplication.Quit 
  Set AccessApplication = Nothing

End Sub


这篇关于Msaccess 2103运行时错误CreateObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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