1.Я получил «Ошибка времени выполнения« 1004 »: нет текущей записи». Я пытался! Клиенты. Адрес, который я пробовал. Поля (5) Я тоже пытался! [Клиенты. Адрес], но ни один из них не работает. Прежде чем пытаться получить доступ к данным, я распечатываю данные. Это было успешно, и я распечатал, что я ожидал, адрес компаний для цитаты.
2. Я пытаюсь сделать одну цитату за раз, и с использованием входной цитаты нет .. Поэтому я добавил предложение "WHERE" в коде (оно было закомментировано). Однако оно не работает.
Вот код (у меня постоянно возникают проблемы с форматированием для копирования кода. Поэтому я использовал изображения):
Dim appExcel As Excel.Application
Dim myWorkbook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim SQL As String
Dim rsl As DAO.Recordset
Dim i As Integer
Dim Message, Title, Default, MyValue
'user input for the quotation no.
Message = "Plz Enter Quotation No" ' Set prompt.
Title = "InputBox Demo" ' Set title.
Default = "SHA-202-0001" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)
'Show user work is being performed
DoCmd.Hourglass (True)
'******************************************************
' RETRIEVE DATA
'******************************************************
'SQL statement to retrieve Article_No from Quotation_Detail table
'SQL = "SELECT Article_No AS [Article No]" & _
'"FROM Quotation_Detail " & _
'"ORDER BY Article_No "
'SQL statement to retrieve Short Name, Company, Person, Telefone, USCI Num from Customers Table and Quotation No,
'Buyer, Revision, Info, Article_No, QUantity, Matchcode and RMB_price from Quotation Query 1
SQL = "SELECT Customers.[Short Name], Customers.Company, Customers.Person, Customers.Telefone, Customers.[E-Mail]," & _
"Customers.Address , Customers.City, Customers.Postcode, Customers.Province, Customers.[USCI Num]," & _
"[Quotation Query1].Buyer , [Quotation Query1].[Our Reference]," & _
"[Quotation Query1].[Quotation Date] , [Quotation Query1].Revision, [Quotation Query1].Info," & _
"[Quotation Query1].Article_No , [Quotation Query1].Quantity, [Quotation Query1].Matchcode," & _
"[Quotation Query1].RMB_price , [Quotation Query Query].[Quotation No], [Quotation Query Query].[Sum Of total]" '& _
"FROM (Customers INNER JOIN ([Quotation Query Query] INNER JOIN Quotation ON [Quotation Query Query].[Quotation No] = Quotation.[Quotation No]) ON Customers.[Short Name] = Quotation.[Buyer]) INNER JOIN [Quotation Query1] ON Customers.[Short Name] = [Quotation Query1].[Buyer]" & _
'"WHERE [Quotation Query Query].[Quotation No] = Myvalue"
'To select only one quotation with the quotation no. to make the quotation but failed with WHERE clause
'Execute query and populate recordset
Set rsl = CurrentDb.OpenRecordset(SQL, dbOpenSnapshot)
'If no data, don't bother opening Excel, just quit
If rsl.RecordCount = 0 Then
MsgBox "No data selected for export", vbInformation + vbOKOnly, "No data exported"
GoTo SubExit
End If
'Loop each row to print data in rsl(0) to test what's in the rsl
'rsl(0) is the short name
'rsl(1) is the company name
' Contrl G to see what have been printed
Do While Not rsl.EOF
Debug.Print rsl(5)
rsl.MoveNext
Loop
Set appExcel = CreateObject("Excel.Application")
Set myWorkbook = appExcel.Workbooks.Open("C:\Users\Cindy\Desktop\Quotation_Master.xlsx")
appExcel.Visible = True
Set xlSheet = myWorkbook.Worksheets(1)
With xlSheet
.Name = "Quotation"
.Cells.Font.Name = "Calibri"
.Cells.Font.Size = 11
'build quotation info
.Range("C16").Value = MyValue
.Range("A6").Value = rsl(5)
.Range("A9").Value = rsl!Customers.Postcode
.Range("B12").Value = rsl!Customers.Telefone
.Range("B13").Value = rsl!Customers.[E-Mail]
.Range("B14").Value = rsl!Customers.[USCI Num]
.Range("F16").Value = rsl![Quotation Query1].Revision
.Range("B17").Value = rsl![Quotation Query1].[Quotation Date]