我在MS Access上的编码有问题。
这里是我的代码,简单的代码,用于控制导入数据的按钮(从MS Access中的表单到另一个MS Access DB(。宏位于受pw保护的数据库中。经过几次测试,我找不到打开和填充pw的好脚本。pw必须包含在脚本中才能自动处理。(使用Public函数可以正确地对用户名进行排序(。
MS Access 365 MSO 16.0 64位版本2108
Private Sub Command35_Click()
Dim AppAccess As Access.Application
Set AppAccess = GetObject("C:Users" & GetUserName & "DatabasesDB Friends.accdb")
AppAccess.Visible = False
AppAccess.DoCmd.RunMacro "Mcr_M_NewFriends"
AppAccess.Quit
Me.Command35.BackColor = RGB(255, 124, 128)
MsgBox "New friends data imported"
End Sub
你能帮我一下吗?谢谢大家。
尝试以下
Private Sub Command35_Click()
Dim acc As Access.Application
Dim db As DAO.Database
Dim strDbName As String
strDbName = "C:database Folderabc.accdb"
Set acc = New Access.Application
acc.Visible = False
acc.OpenCurrentDatabase strDbName, False, "password"
Set db = acc.CurrentDb() '
acc.UserControl = True
acc.DoCmd.RunMacro "Mcr_M_NewFriends"
acc.Quit
Me.Command35.BackColor = RGB(255, 124, 128)
MsgBox "New friends data imported"
End Sub