เรียน อาจารย์ snasui
ติกปัญหา
1.ในส่วนของการ insert ข้อมูลเข้าไปใน server โดยผมได้ลองเขียน Code เพื่อเก็บข้อมูลที่ใส่ไปในบรรทัดที่ 1-25 ไว้ที่บรรทัดที่ 27 (คลิกปุ่ม Getdata) แล้วลอง คลิกปุ่ม Save แล้ว error ครับ ไม่แน่ใจว่าต้องปรับ Code อย่างไรครับ ขอบคุณครับ
Code: Select all
Sub SaveData()
Dim sFile As String, sh As Worksheet
Dim sCnstr As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String, shtName As String
Dim arr() As Variant, i As Integer, j As Integer
sFile = "\\10.21.4.97\File Sharing2\DataPricing\All Data Estimated.xlsx"
shtName = "[Data$]"
strSql = "INSERT INTO [sFile$]" & _
" SELECT * FROM [Excel 12.0 Macro;HDR=Yes;" & _
" Database=" & ThisWorkbook.FullName & ";Readonly=False].[Input$A26:CR27]"
sCnstr.CursorLocation = adUseClient
sCnstr.Open "Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source=" & sFile & ";" _
& "Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
rs.Open sql, sCnstr
Set sCnstr = Nothing
Set rs = Nothing
End Sub
2.ในส่วนของ input data
เลข Ref No ช่อง F6 จะไม่ใส่ค่า ระบบจะ Generate ให้อัตโนมัติ
โดยกำหนด = ปี-เดือน-วัน-Running Number และจะ run ไปเรื่อยๆ ครับ
โดยที่ปี = ปีปัจุบัน - 2000
เช่นปี 2022 เดือน พฤศจิกายน วันที่ 20
เลข Refno ที่ได้ = 22-11-20-0001
ถ้าเป็นวันใหม่จะเริ่ม 0001 ใหม่ครับ อาจารย์พอมีวิธีแนะนำหรือไม่ครับ ขอบคุณครับ
Code: Select all
Sub Savetofile_Click()
Dim r As Integer
Dim i As Integer
i = 1
r = Sheets("input").Cells(Rows.Count, 1).End(xlUp).Row + 1
Sheets("input").Cells(r, 2).Value = Day(Date)
Sheets("input").Cells(r, 3).Value = Month(Date)
Sheets("input").Cells(r, 4).Value = Year(Date) - 2000
Sheets("input").Cells(r, 5).Value = i
i = i + 1
Sheets("input").Cells(r, 2).NumberFormat = "00"
Sheets("input").Cells(r, 3).NumberFormat = "00"
Sheets("input").Cells(r, 5).NumberFormat = "0000"
Refno = Sheets("input").Cells(r, 4).Text & "-" & Sheets("input").Cells(r, 3).Text & "-" & Sheets("input").Cells(r, 2).Text & "-" & Sheets("input").Cells(r, 5).Text
Sheets("input").Cells(r, 1).Value = Refno
Sheets("Input").Range("InputRefNo") = Refno
Sheets("input").Cells(r, 6).Value = Sheets("Input").Range("InputName").Value
Sheets("input").Cells(r, 7).Value = Sheets("Input").Range("InputHN").Value
Sheets("input").Cells(r, 8).Value = Sheets("Input").Range("C12").Value
Sheets("input").Cells(r, 9).Value = Sheets("Input").Range("InputPayer").Value
Sheets("Input").Range("InputEstimateDateTime").Value = Now
Sheets("input").Cells(r, 95).Value = Sheets("Input").Range("InputEstimateDateTime").Value
End Sub
[Code]
You do not have the required permissions to view the files attached to this post.