Consulting

Results 1 to 2 of 2

Thread: how to check if already exist in db

  1. #1

    how to check if already exist in db

    Hello,

    i was wondering how we can check with our code if the date already exist if so we want to ignore it
    and still creating the other values

    Set ws = ThisWorkbook.Sheets("Sheet5")
    ws.Activate
    
    
    
    
    
    
    Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
    
    
    Set cn = New ADODB.Connection
    cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\Database.ACCDB" & ";Jet OLEDB:Database Password='12345';Mode=Share Exclusive"
    
    
    Set rs = New ADODB.Recordset
    rs.Open "TBL_ImportList", cn, adOpenKeyset, adLockOptimistic, adCmdTable
    
    
    r = 9 ' the start row in the worksheet
    Do While Len(Range("A" & r).Formula) > 0
    ' repeat until first empty cell in column A
    With rs
    .AddNew ' create a new record
    .Fields("m_datetime") = Range("F" & r).value
    .Update ' stores the new record
    End With
    
    
    r = r + 1 ' next row
    Loop

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    If Field <> "" or Field <> 0 Then Field = Date

    "" or 0 depends on the Field Data Type
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •