Access + VBA. Findfirst дает ошибку при поиске по таблице tabCC по второму параметру - строке из связанной таблицы tabBR. Помогите пожалуйста нЕучу((
Код:
Sub ExcelImportTest_ver1_MV()
Dim objExcel As Object ' Excel.Application
Dim objWorkbook As Object ' Excel.Workbook
Dim dbs As DAO.Database, tab1 As DAO.Recordset, tabCC As DAO.Recordset, tabBR As DAO.Recordset
Dim strSQL As String
Dim a1 As Variant
Dim b_str As String
Dim tabBR_Rec As Object
Set objExcel = CreateObject("Excel.Application") ' New Excel.Application
Set objWorkbook = objExcel.Workbooks.Open("D:\Access\2014_01_MV.xls")
Set dbs = CurrentDb
Set tab1 = dbs.OpenRecordset("Data_Import_PL_CSt")
Set tabCC = dbs.OpenRecordset("CostCentre", DAO.dbOpenDynaset)
Set tabPL = dbs.OpenRecordset("PL", DAO.dbOpenDynaset)
Set tabBR = dbs.OpenRecordset("Branch", DAO.dbOpenDynaset)
intRow = 2
intCol = 2
Do Until objExcel.Sheets("sheet1").Cells(1, intCol).Value = ""
Do Until objExcel.Sheets("sheet1").Cells(intRow, 1).Value = ""
a1 = objExcel.Sheets("sheet1").Cells(intRow, intCol).Value
b1 = objExcel.Cells(1, intCol).Value
c1 = objExcel.Cells(intRow, 1).Value
'b_str = CStr(b1)
'A2 = objExcel.Cells(intRow, 2).Value
'//anton <<
If (Not IsNull(a1)) And (Not IsEmpty(a1)) Then
tabBR.FindFirst "[Name_Code] = 'MV'"
Set tabBR_Rec = tabBR(0) tabPL.FindFirst "[Code_PL] = '" & c1 & "'"
If tabPL.NoMatch Then
MsgBox ("всё плохо PL")
MsgBox (" c1 ")
Else
tabCC.FindFirst "([Code_CC] = '" & b1 & "') " & " And ([Branch] = '" & tabBR_Rec & "')" 'tabCC.FindFirst "[Code_CC] = '" & b1 & "'" And "[Branch] = " & tabBR_Rec &
'And "[Branch] = ' & tabBR & '"
'And "[Branch] = ' 2 '"
If tabCC.NoMatch Then
MsgBox ("всё плохо CC")
MsgBox (" b1 ")
Else
tab1.AddNew
tab1!CostCentre.Value = tabCC(0)
tab1!PL.Value = tabPL(0)
tab1!Summa.Value = objExcel.Sheets("sheet1").Cells(intRow, intCol).Value
tab1!Branch.Value = tabBR(0)
tab1!Period.Value = "01_2014"
tab1.Update
End If
End If
http://www.sql.ru/forum/1090467/access-vba-findfirst-daet-oshibku-pri-poiske-po-tablice-po-vtoromu-parametru