connstr = "DRIVER={Microsoft ODBC for Oracle};SERVER=" & strDBName & ";UID=" & strUserID & ";PWD=" & strPassword & ";"
ConnDB.CursorLocation = adUseServer
ConnDB.Open connstr
DoCmd.SetWarnings 0
DSTAR = Forms!Open!DSTAR
DEND = Forms!Open!DEND
strSQL = "SELECT t1.A, t1.B" _
& " FROM TABL1 t1 INNER JOIN TABLE2 t2 ON t1.XX_ID = t2.XX_ID" _
& " WHERE ((to_CHAR(t1.DATE1,'yyyy-mm-dd') Between '" & DSTAR & "' And '" & DEND & "') AND (SUBSTR(t1.ABC,1,3)= 'XXX') AND ((t2.DEF)='YYY'))"
rs.Open "test", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rst.Open strSQL, ConnDB, 3, adLockPessimistic
'MsgBox rst.RecordCount
If rst.RecordCount > 0 Then
rst.MoveFirst
Do Until rst.EOF
rs.AddNew
rs![a] = rst("A")
rs![B] = rst("B")
rs.Update
rst.MoveNext
Loop
End If
MsgBox "ok"
rs.Close
Set rs = Nothing
rst.Close
Set rst = Nothing
ConnDB.Close
Set ConnDB = Nothing