2

我想我很接近我只是不知道确切的语法。

我正在尝试使用 VBA 根据我的表 Stock Conversion 中的 SCID(主键)的值选择一条记录。

If LookUp("Source PC", "Stock Conversion") Is Null Then
sc1.AddNew
sc1.Fields("[Source PC]").Value = Me.cmbSource.Value
sc1.Update
End If

这是我现在拥有的代码,如您所见,我只希望在值为 Null 时填充该字段。它需要找到 SCID = Record 的 Source PC。

在此先感谢,鲍勃 P

4

1 回答 1

3

这是您应该使用记录集的地方。

Dim rs As DAO.Recordset
Dim sSQL As String

'SQL to select a record from a table MyTable based on a field or control
'called ID in the current form
sSQL="Select Id,Field1 from MyTable Where Id=" & Me.ID

'Open the recordset
Set rs = CurrentDB.OpenRecordset(sSQL)
'Test for End Of File to see if the recordset is empty ...
If rs.Eof Then
   'add a new record
   rs.AddNew 
   rs!Field1 = "Something"
   rs.Update
Else
   '... otherwise, do what you want with the record,
   'let us say edit.
   rs.edit
   rs!Field1 = "Something"
   rs.Update
End If
于 2012-10-03T12:20:11.057 回答