Hi, I have a Access table where I would like to set fields values ( swh1_ct and swInfa_ct) to null if my pdmH1_ct or pdmInfA_ct fields have values greater than 0. and vice-versa.
Can some one point me to the error in my code?

Sub update_field()


   Dim objDB As DAO.Database
   Dim mytbl As DAO.Recordset
    Set objDB = CurrentDb()
    Set mytbl = objDB.OpenRecordset("QC_Details")
    Dim pdmH1_Ct As Field
    Dim pdmInfA_Ct As Field
    Dim SwInfA_Ct As Field
    Dim SwH1_ct As Field
    


   If mytbl.Fields(pdmH1_Ct).Value > 0 Or mytbl.Fields(pdmInfA_Ct).Value > 0 Then
       mytbl.Fields(SwInfA_Ct).Value = Null
       mytbl.Fields(SwH1_ct).Value = Null
    End If
    
    If mytbl.Fields(SwH1_ct).Value > 0 Or mytbl.Fields(SwInfA_Ct).Value > 0 Then
       mytbl.Fields(pdmInfA_Ct).Value = Null
       mytbl.Fields(pdmH1_Ct).Value = Null
    End If
    
End Sub

Instead of being = Null, have you tried = vbNull or = vbNullString

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.