Dim DB As Database
Dim rs As DAO.Recordset
set DB=currentdb() '<<< ADD this line
For i = Val(txtNoFrom) To Val(txtNoTO)
cmbCarInsert.SetFocus
DB.Execute "Insert into tblPetrolDetails (PetrolID, Carno, voucherno,vouchervalue ) " & _
" values (" & ID & ",'" & cmbCarInsert.Text & "','" & i & "'," & Val(txtInsertValue) & ") "
Next