我认为我很接近我只是不知道确切的语法。
我正在尝试使用VBA根据我的表库存转换中的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的源PC。
提前致谢, Bob P
答案 0 :(得分: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