这是我认为您正在努力实现的目标的基本概述。
当您对对象进行完整引用时,您的 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