Знайти помилку в коді Visual Basic
Знайти помилку в коді та підкоригувати код , помилка зазначена в рядка 1, 2
Dim sourceDB As Database
Dim destDB As Database
Dim tblDef As TableDef
Dim RS As Recordset
Dim fld As Field
Dim strSQL As String
Dim newSQL As String
Dim skipColumns As String
Set sourceDB = OpenDatabase("C:\Program Files\out.mdb", False, False, ";PWD=555")
Set destDB = OpenDatabase("C:\Program Files\in.mdb", False, False, ";PWD=555")
For Each tblDef In sourceDB.TableDefs
If Not (tblDef.Name Like "MSys*" Or tblDef.Name Like "~*") Then ' ignore system tables
strSQL = "SELECT * FROM " & tblDef.Name
Set RS = sourceDB.OpenRecordset(strSQL)
newSQL = "INSERT INTO " & tblDef.Name & " ("
skipColumns = ""
t = 0
For Each fld In RS.Fields
If Not tblDef.Fields(fld.Name) Is Nothing Then ' field exists in destination table
newSQL = newSQL & "[" & fld.Name & "], "
Else ' field doesn't exist in destination table
skipColumns = skipColumns & "[" & fld.Name & "], "
End If
Next fld
newSQL = Left(newSQL, Len(newSQL) - 2) & ") VALUES ("
' add parameters for columns that exist in destination table
For Each fld In tblDef.Fields
newSQL = newSQL & "?, "
Next fld
newSQL = Left(newSQL, Len(newSQL) - 2) & ")"
' insert records into destination table
RS.MoveFirst
Do Until RS.EOF
Dim qdf As QueryDef
Set qdf = destDB.CreateQueryDef("", newSQL)
' запит "INSERT INTO Aktyvni ([Nomer], [Spivrobitnyk], [Zarer], [Vyjshov], [Admin], [Nomer_kom]) VALUES (?, ?, ?, ?, ?, ?)"
' 1___________________Таблиця запиту qdf не має стопців, які переносяться з запиту
Dim i As Integer
i = 0
For Each fld In RS.Fields
If Not tblDef.Fields(fld.Name) Is Nothing Then ' ïîëå ³ñíóº â òàáëèö³ ïðèçíà÷åííÿ
'2_____________________ і на цьому моменті вибиває помилку
qdf.Parameters(i) = fld.Value
End If
i = i + 1
Next fld
qdf.Execute
RS.MoveNext
Loop
RS.Close
If Len(skipColumns) > 0 Then ' some columns were skipped
MsgBox "Skipped columns in table " & tblDef.Name & ": " & Left(skipColumns, Len(skipColumns) - 2)
End If
End If
Next tblDef
sourceDB.Close
destDB.Close
Applications 2
-
На перший погляд ви маєте присвоїти значення індексу тільки тоді коли поле існує в таблиці. Треба змінювати цикл For Each fld In RS.Fields...
-
Проблема в тому що таблиця запиту qdf не формується від команди Set qdf = destDB.CreateQueryDef("", newSQL), де newSQL= "INSERT INTO Aktyvni (Nomer, Spivrobitnyk, Zarer, Vyjshov, Admin, Nomer_kom) VALUES (?, ?, ?, ?, ?, ?)"
-
Основне завдання перенести з бази даних в іншу дані , по таблицях, але в оновленій базі деяких стовпців в таблиці може не буди
-
Current freelance projects in the category Desktop Apps
Modification in the emulator's operation
45 USD
Hello. I downloaded the Gaminator CF Final slot machine emulator from the Internet. I really liked it, but there are some issues. There is an admin panel, but it opens freely and cannot be closed at all. It only closes along with the application. Also, the data does not save… Desktop Apps ∙ 1 day 15 hours back ∙ 10 proposals |
Development of custom software (Android application + CMS) for SUNMI K2 self-service kiosks (Fast food)
23 USD
We are looking for an experienced team or a Middle/Senior Android developer (possibly with Full-stack skills) to create proprietary software for self-service kiosks for a fast food retail chain. Currently, our terminals operate on a ready-made cloud integrator, but we are… Content Management Systems, Desktop Apps ∙ 6 days 10 hours back ∙ 23 proposals |
It is necessary to migrate the current working program from FoxPro to C#.Hello everyone! We have a program in FoxPro (it has several modules, it's an accounting program), we have the source code of the program, and if necessary, we can consult with people who support the current program. What needs to be done: 1. Analyze how everything works,… C#, Desktop Apps ∙ 11 days 18 hours back ∙ 19 proposals |