Advertisement
sergrv

price_form

Mar 30th, 2020
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub Form_Open(Cancel As Integer)
  5. Debug.Print "---price_form----"
  6.  
  7. Me.[subform_price].SourceObject = "subform_price"
  8. Me.[subform_price].Form.RecordsetType = 0
  9. Me.[subform_price].Form.RecordSource = "SELECT * FROM price_view;"
  10.  
  11. End Sub
  12.  
  13. Private Sub search_field_AfterUpdate()
  14. filter_sub
  15. End Sub
  16.  
  17. Private Sub in_stock_flag_AfterUpdate()
  18. filter_sub
  19. End Sub
  20.  
  21.  
  22. Public Sub filter_sub()
  23. Dim sql$, where$, order$
  24. Dim i As Integer
  25.  
  26. sql$ = "SELECT GOODS.ID, GOODS.NAME, GOODS.BUY_PRICE, GOODS.SKLAD1, GOODS.SKLAD2, GOODS.LIMIT, GOODS.BOX, GOODS.BUY_PRICE * (GOODS.SKLAD1 + GOODS.SKLAD2) AS SUMMA" _
  27. & " FROM GOODS "
  28.  
  29. where$ = " WHERE GOODS.IS_DELETED = 0"
  30.  
  31. order$ = " ORDER BY GOODS.NAME;"
  32.  
  33. If in_stock_flag Then
  34. where$ = where$ & " AND (GOODS.SKLAD1>0 OR GOODS.SKLAD2>0)"
  35. End If
  36.  
  37. If search_field.Value <> 0 Then
  38. where$ = where$ & " AND Lcase(GOODS.NAME) Like '*" & check_txt(LCase(search_field.Value)) & "*'"
  39. End If
  40.  
  41. Debug.Print where$
  42.  
  43. Me.[subform_price].Form.RecordSource = (sql$ & where$ & order$)
  44.  
  45. End Sub
  46.  
  47.  
  48. Private Sub Excel_button_Click()
  49. Debug.Print "excel_button_Click()"
  50.  
  51. Dim rs As DAO.Recordset
  52. Set rs = Me.[subform_price].Form.RecordsetClone
  53.  
  54. If rs.BOF Then
  55. Exit Sub
  56. End If
  57. DoCmd.OpenForm "modal_wait_please"
  58.  
  59. Dim oExcel As Object
  60. Set oExcel = CreateObject("Excel.application")
  61. oExcel.Application.Visible = False
  62. 'oExcel.Application.windowsstate = xlMaximized
  63. oExcel.Workbooks.Add
  64. oExcel.DisplayAlerts = False
  65. oExcel.Caption = "Price-list"
  66. 'oExcel.ActiveSheet.PageSetup.LeftMargin = 30
  67. 'oExcel.ActiveSheet.PageSetup.RightMargin = 30
  68. 'oExcel.ActiveSheet.PageSetup.TopMargin = 30
  69. 'oExcel.ActiveSheet.PageSetup.BottomMargin = 30
  70. 'oExcel.ActiveSheet.PageSetup.Orientation = 1 ' xlPortrait
  71. 'oExcel.ActiveSheet.PageSetup.PaperSize = 9  'xlPaperA4
  72. oExcel.Cells.Font.NAME = "Calibri"
  73. oExcel.Cells.Font.Size = 11
  74.  
  75. With oExcel
  76.     .Columns("A").ColumnWidth = 40
  77.     .Columns("B").ColumnWidth = 12
  78.     .Columns("C").ColumnWidth = 12
  79.     .Columns("D").ColumnWidth = 12
  80.     .Columns("E").ColumnWidth = 14
  81.     .Columns("F").ColumnWidth = 14
  82.    
  83.     .Range("A1").Value = "Price-list"
  84.    
  85.     .Range("A4").Value = "Model"
  86.     .Range("B4").Value = "sklad 1"
  87.     .Range("C4").Value = "sklad 2"
  88.     .Range("D4").Value = "BUY_PRICE"
  89.     .Range("E4").Value = "Sum sklad 1"
  90.     .Range("F4").Value = "Sum sklad 2"
  91.    
  92. Dim nrow As Integer
  93. nrow = 5
  94.  
  95. rs.MoveFirst
  96.  
  97. Do While Not rs.EOF
  98.       .Range("A" & nrow).Value = rs!NAME
  99.       .Range("B" & nrow).Value = rs!sklad1
  100.       .Range("C" & nrow).Value = rs!sklad2
  101.       .Range("D" & nrow).Value = CDbl(Nz(rs!BUY_PRICE))
  102.       .Range("E" & nrow).FormulaR1C1 = Nz(rs!sklad1) * CDbl(Nz(rs!BUY_PRICE))
  103.       .Range("F" & nrow).FormulaR1C1 = Nz(rs!sklad2) * CDbl(Nz(rs!BUY_PRICE))
  104.      
  105.  nrow = nrow + 1
  106.  
  107.  rs.MoveNext
  108. Loop
  109.    
  110.     .Range("D5:F" & nrow).NumberFormat = "0.00;-0.00;#"
  111.  
  112.     .Range("E" & nrow).Formula = "=SUM(E5:E" & Trim(Str(nrow - 1)) & ")"
  113.     .Range("F" & nrow).Formula = "=SUM(F5:F" & Trim(Str(nrow - 1)) & ")"
  114.     .Range("E5:F" & nrow).NumberFormat = "[Blue]0.00;[Red]-0.00;#"
  115.    
  116.     .Range("A5:A" & (nrow - 1)).HorizontalAlignment = xlLeft
  117.     .Range("B4:F" & Trim(Str(nrow - 1))).HorizontalAlignment = xlCenter
  118.  
  119. 'Borders
  120.    .Range("A4:F" & (nrow - 1)).Select
  121.     .Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  122.     .Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  123.     With .Selection.Borders(xlEdgeLeft)
  124.         .LineStyle = xlContinuous
  125.         .ColorIndex = 0
  126.         .TintAndShade = 0
  127.         .Weight = xlThin
  128.     End With
  129.     With .Selection.Borders(xlEdgeTop)
  130.         .LineStyle = xlContinuous
  131.         .ColorIndex = 0
  132.         .TintAndShade = 0
  133.         .Weight = xlThin
  134.     End With
  135.     With .Selection.Borders(xlEdgeBottom)
  136.         .LineStyle = xlContinuous
  137.         .ColorIndex = 0
  138.         .TintAndShade = 0
  139.         .Weight = xlThin
  140.     End With
  141.     With .Selection.Borders(xlEdgeRight)
  142.         .LineStyle = xlContinuous
  143.         .ColorIndex = 0
  144.         .TintAndShade = 0
  145.         .Weight = xlThin
  146.     End With
  147.     With .Selection.Borders(xlInsideVertical)
  148.         .LineStyle = xlContinuous
  149.         .ColorIndex = 0
  150.         .TintAndShade = 0
  151.         .Weight = xlThin
  152.     End With
  153.     With .Selection.Borders(xlInsideHorizontal)
  154.         .LineStyle = xlContinuous
  155.         .ColorIndex = 0
  156.         .TintAndShade = 0
  157.         .Weight = xlThin
  158.     End With
  159.    
  160.  
  161.  rs.Close
  162.  Set rs = Nothing
  163.  
  164.   Dim Path$
  165.   Path$ = get_path()
  166.   Path$ = Path$ & "\price.xls"
  167.    On Error Resume Next
  168.    .ActiveWorkbook.SaveAs FileName:= _
  169.         Path$, FileFormat:= _
  170.         xlExcel8, PASSWORD:="", WriteResPassword:="", ReadOnlyRecommended:=False _
  171.         , CreateBackup:=False
  172.    
  173. DoCmd.Close acForm, "modal_wait_please"
  174. .Application.Visible = True
  175.  
  176. 'Freeze Panes
  177. .Application.ScreenUpdating = True
  178. .Cells(5, 2).Select
  179. .ActiveWindow.FreezePanes = True
  180.  
  181. End With
  182.  
  183. Set oExcel = Nothing
  184.  
  185. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement