Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access VBA访问中的连接_Ms Access_Vba - Fatal编程技术网

Ms access VBA访问中的连接

Ms access VBA访问中的连接,ms-access,vba,Ms Access,Vba,如何修复用VBA编写的“更新”SQL查询?我想将“Name”字段更新为表单中连接2个字段的值。我写了这段代码,但不起作用,有什么建议吗 这是我的密码: strSQL = "UPDATE dbo.Soferi_test SET Name = '" & Me![subform_soferi].Form!numele & Me![subform_soferi].Form!prenumele &

如何修复用VBA编写的“更新”SQL查询?我想将“Name”字段更新为表单中连接2个字段的值。我写了这段代码,但不起作用,有什么建议吗

这是我的密码:

strSQL = "UPDATE dbo.Soferi_test SET Name = '" & Me![subform_soferi].Form!numele
                                               & Me![subform_soferi].Form!prenumele & _
          "',Cipti = '" & Me![subform_soferi].Form!certificat_cipti & _
          "' WHERE IDNO = " & Me![subform_soferi].Form!IDNO

以下是我相信你正在努力实现的目标的基本轮廓

  • 在我看来,表单字段是从表单上的子表单引用的
当您放入对对象的完整引用时,您的sql看起来非常复杂,因此我更愿意

  • 创建一些变量
  • 将表单对象指定给变量,然后
  • 在sql中引用变量
我认为这使程序更具可读性。您可以通过表单上的按钮调用以下命令:

'****Update a table based on the values on a subform****'
'Table name:    dbo.Soferi_test
'Form Name:     frmMain
'Subform Name:  subform_soferi

Sub updateTable()

'Declare your variables which will be used in the sql string

Dim strSQL As String
Dim strNumele As String
Dim strPrenumele As String
Dim strCertificatCipti As String
Dim strIDNO As String

'Assign your variables to the form\subform objects
'You should also add some validation to check that the fields are not null

strNumele = Form_frmMain.subform_soferi!numele
strPrenumele = Form_frmMain.subform_soferi!prenumele
strCertificatCipti = Form_frmMain.subform_soferi!certificat_cipti
strIDNO = Form_frmMain.subform_soferi!IDNO

'Build your sql string
strSQL = "UPDATE dbo.Soferi_test SET Soferi_test.Name = '" & strNumele & strPrenumele & "', Cipti = '" & strCertificatCipti & "' WHERE (((Soferi_test.IDNO)='" & strIDNO & "'));"

'Execute the sql
CurrentDb.Execute strSQL

'You will want to put in some error handling here

End Sub

你说的“它不起作用”到底是什么意思?它是否会导致错误,或者它只是不符合您的意愿?您希望在这两个字段之间有任何区别吗?此时,它们被直接粘在一起,没有分离器。最后你也缺少了
&“
。当我单击按钮
debug时,他们不会进行任何更新。打印
sql并将输出粘贴到你的问题中