2017-05-08 51 views

回答

0

這將做你想做的。

Private Sub Command1_Click() 

Dim Rs As Recordset, strSQL As String, CurData As Variant 
'Note: Set a reference to the Microsoft DAO Object library via Tools | References 

'Amend this to indicate the table and sort by the autonumber id 
strSQL = "SELECT * FROM YOUR_TABLE" 

'Opens a recordset (like a query) to the table 
Set Rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges) 


'Loop through the records in the table and if the previous row didnt have data in the 
'Repaired_By field then populate the previous Repaired_By data. Assumes the first record is 
'populated with info 
Rs.MoveLast 
Rs.MoveFirst 
Do 
    If Rs!CONTACT_ID = "" Or IsNull(Rs!CONTACT_ID) Then 
     'This field is blank so populate the info from the variable 
     Rs.Edit 
     Rs!CONTACT_ID.Value = CurData 
     Rs.Update 
    Else 
     'This field isnt blank so store the info in the variable in case the next record is blank 
     CurData = Rs!CONTACT_ID.Value 
    End If 
    Rs.MoveNext 
Loop While Not Rs.EOF 

'Remove the recordset object from memory 
Rs.Close 
Set Rs = Nothing 
End Sub