0
저는 VBA를 처음 사용하지만 잘하고 싶습니다.제품 1, 제품 2 ... 등에서 값을 가져옵니다. VBA에서 루프가 있습니다.
나는 다른 클라이언트와 테이블을 가지고 있으며 모든 클라이언트는 자신의 ID를 가지고 있습니다.
표에서 모든 클라이언트는 다른 수의 제품을 구입합니다. 예를 들어 ID가 3 인 클라이언트는 3 개의 제품을 구입합니다. 표에서 product1, product2, product3으로 이름을 짓습니다.
Dim intTotal, totalCompra As Double
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim rs As DAO.Recordset
Dim cantidad As Integer
Dim intCantidad As Integer
Dim intPrecio As Double
Set wApp = New Word.Application
Set wDoc = wApp.Documents.Open("C:\...\factura_alcazaba.docx")
Set rs = CurrentDb.OpenRecordset("Select * FROM Ventas_Alcazaba WHERE ID =" & idInt & ";")
wDoc.Bookmarks("Name").Range.Text = Nz(rs!Nombre_cliente, "")
wDoc.Bookmarks("NIF").Range.Text = Nz(rs!NIF, "")
wDoc.Bookmarks("Fecha").Range.Text = Nz(rs!Fecha, "")
cantidad = Nz(rs!Numero_productos, "")
If Not IsEmpty(rs!Cantidad_prod1) Then
intCantidad = rs!Cantidad_prod1
wDoc.Bookmarks("cantidad1").Range.Text = Nz(rs!Cantidad_prod1, "")
wDoc.Bookmarks("descripcion1").Range.Text = Nz(rs!Descripcion_prod1, "")
intPrecio = rs!Precio_prod1
intTotal = intPrecio * intCantidad
totalCompra = totalCompra + intTotal
wDoc.Bookmarks("precio1").Range.Text = Nz(intPrecio, "")
wDoc.Bookmarks("prod1_total").Range.Text = Nz(intTotal, "")
End If
'For i = 1 To cantidad
'intCantidad = rs!Cantidad_prod + i
'wDoc.Bookmarks("cantidad" + i).Range.Text = Nz(rs!["Cantidad_prod" & i], "")
' wDoc.Bookmarks("descripcion" & i).Range.Text = Nz(rs!["Descripcion_prod" + i], "")
' intPrecio = Nz(rs!["Precio_prod" & i], "")
'intTotal = intPrecio * intCantidad
' totalCompra = totalCompra + intTotal
' wDoc.Bookmarks("precio1").Range.Text = Nz(intPrecio, "")
' wDoc.Bookmarks("prod1_total").Range.Text = Nz(intTotal, "")
'Next i
wDoc.SaveAs2 "C:\Factura_" & rs!ID & ".docx"
wDoc.Close False
wApp.Quit
만약 내가 테이블에 모든 값을 얻을 수 있다면. 그러나 이것은 매우 비효율적이며 루프로 처리하고 싶습니다. 하지만 다른 제품을 호출하는 방법을 모르겠지만 최종 번호 만 변경합니다.
Uhmmm, 나는 알고있다, 나는 단순한 것을 원하기 때문이다. 그것은 내 동생에게 은혜입니다. 동생이 판매자가 아니기 때문에 최대 10 개 제품을 추가하겠습니다. 그는 다른 사업을 위해서만 청구서를 발행하기 때문에 더 많은 제품이 필요하다면 직접 추가 할 수 있습니다. 나는 그가 보통 hehe를 사용하기 때문에 이것을 만든다. – AntoIba
그래,하지만 문제는 : 당신이 그것을 단순하게 만들지 않으면, 너 자신을 더 힘들게 만든다. 그리고 그 사람. 클라이언트 - 제품 - 주문 - 주문 위치 테이블 구조는 Northwind 예제 데이터베이스를 포함하여 거의 모든 데이터베이스 예제에 있습니다 (필자는 생각합니다). 그것은 처음에는 올바르게 할 돈을 지불합니다. – Andre
예, 알고 있습니다. 문제는 내가 접근이 좋았다는 것을 몰랐다는 것이 었습니다. 나는 Products, Clients, Sales 테이블과 키 ID를 가진 테이블을 생성 할 것이다. 조금 더 시간이 걸릴 것이지만 더 좋을 것입니다. – AntoIba