Function AddNewStaffToServer() As Boolean
Const adCmdText As Integer = 1, _
adClipString As Integer = 2, _
MAX_ROWS As Integer = 1000, _
MAX_ID As String = "[[MAX_ID]]"
Const SQL_INSERT As String = _
"INSERT INTO tblStaff (" & vbNewLine & _
"EmpName, EmpPassword, UserRights, tpin, bhfId, userId, adrs, cntc, " & vbNewLine & _
"authCd, remark, useYn, regrNm, regrId, modrNm, modrId, Status" & vbNewLine & _
") VALUES " & vbNewLine
Const SQL_STAFF_NEW As String = _
"SELECT TOP " & MAX_ROWS & " " & vbNewLine & _
"SQLStr(EmpName), SQLStr(EmpPassword), SQLStr(UserRights), tpin, bhfId, userId, adrs, cntc, " & vbNewLine & _
"authCd, SQLStr(remark), useYn, regrNm, regrId, modrNm, modrId, SQLStr(Status)" & vbNewLine & _
"FROM tblStaffNew " & vbNewLine & _
"WHERE ID > " & MAX_ID & " " & vbNewLine & _
"ORDER BY ID;"
Dim values As String, _
strCN As String, _
numRecs As Integer, _
iterations As Integer, _
lastID As Long, _
i As Integer
numRecs = DCount("*", "tblStaffNew")
iterations = (numRecs \ MAX_ROWS) + 1
With CurrentDb
strCN = .TableDefs("tblStaff").Connect
With .CreateQueryDef(vbNullString)
.Connect = strCN
.ReturnsRecords = False
For i = 1 To iterations
With CurrentProject.Connection.Execute(Replace(SQL_STAFF_NEW, MAX_ID, lastID), adCmdText)
If Not .EOF Then
values = .GetString(adClipString, MAX_ROWS, ", ", ")," & vbNewLine & " (", "NULL")
End If
.MoveLast
lastID = .Fields("ID")
.Close
End With
If Len(values) Then
.SQL = SQL_INSERT & " (" & values & ");"
Debug.Print .SQL
.Execute dbFailOnError
values = vbNullString
End If
Next i
End With
End With
AddNewStaffToServer = Err = 0
End Function