2

是否可以仅使用 VBA 而不是使用 SQL 来复制它?

txtSCDate.Value = "SELECT [SC Date] FROM [Stock Conversion] WHERE [SCID] = " & txtSCNumber.Value & ";"

如果不是,那么如何从 VBA 运行该 SQL?

在此先感谢,鲍勃 P

4

1 回答 1

3

您可以使用 DLookUp:

txtSCDate.Value = DlookUp("[SC Date]","[Stock Conversion]","SCID = " _
                & txtSCNumber.Value)

请注意,您可以将文本框的控制源设置为域函数,例如 DLookUp。

如果你想使用 SQL,那么:

Dim rs As Recordset

sSQL = "SELECT [SC Date] FROM [Stock Conversion] WHERE SCID = " _
     & txtSCNumber.Value
Set rs = CurrentDB.Openrecordset(sSQL)
Me.txtSCNumber = rs![SC date]
于 2012-10-03T09:00:30.077 回答