0% found this document useful (0 votes)
2 views

Script Engineer

The document contains a VBA script that generates a file name for well parameters based on the date, opens the corresponding Excel workbook, and populates a database with data from the workbook. It checks for empty or invalid values and assigns default values when necessary. Finally, it saves the updated database and displays a message box indicating the completion of the update.

Uploaded by

Youcef Slimi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Script Engineer

The document contains a VBA script that generates a file name for well parameters based on the date, opens the corresponding Excel workbook, and populates a database with data from the workbook. It checks for empty or invalid values and assigns default values when necessary. Finally, it saves the updated database and displays a message box indicating the completion of the update.

Uploaded by

Youcef Slimi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

If Month(FileCountr) < 10 Then

If Day(FileCountr) < 10 Then


FileString = "well parameters " & CStr(Year(FileCountr)) & "-0" &
CStr(Month(FileCountr)) & "-0" & CStr(Day(FileCountr)) & ".xlsx"
Else
FileString = "well parameters " & CStr(Year(FileCountr)) & "-0" &
CStr(Month(FileCountr)) & "-" & CStr(Day(FileCountr)) & ".xlsx"
End If
Else
If Day(FileCountr) < 10 Then
FileString = "well parameters " & CStr(Year(FileCountr)) & "-" &
CStr(Month(FileCountr)) & "-0" & CStr(Day(FileCountr)) & ".xlsx"
Else
FileString = "well parameters " & CStr(Year(FileCountr)) & "-" &
CStr(Month(FileCountr)) & "-" & CStr(Day(FileCountr)) & ".xlsx"
End If
End If

With ews
.Workbooks.Open CurrentProject.Path & "\Daily well parameters\" &
FileString
.Visible = True
End With

With rst
.Open "DAI_WellParameter", cnn, adOpenKeyset, adLockOptimistic,
adCmdTableDirect
ews.Sheets(1).Select
k=1
j=1
DoTotal = ews.WorksheetFunction.CountA(ews.Range("C9:C999")) + 1
Do Until (k = DoTotal)
If Not IsEmpty(ews.Cells(j + 8, 3)) Then
.AddNew
.Fields("WH_Date").Value = FileCountr
.Fields("WH_Time").Value = ews.Cells(j + 8, 3)
If Not IsEmpty(ews.Cells(j + 8, 2)) Then
WellName = ews.Cells(j + 8, 2)
End If
.Fields("WH_WellID").Value = WellName
If IsEmpty(ews.Cells(j + 8, 4)) Or ews.Cells(j + 8, 4) = 0 Or Not
IsNumeric(ews.Cells(j + 8, 4)) Then
.Fields("WH_Choke").Value = 0
.Fields("WH_THP").Value = 0
.Fields("WH_THT").Value = 0
.Fields("WH_FLP").Value = 0
.Fields("WH_FLT").Value = 0
.Fields("WH_AAnnP").Value = 0
.Fields("WH_BAnnP").Value = 0
.Fields("WH_CAnnP").Value = 0
.Fields("WH_Scale").Value = 0
.Fields("WH_Corrs").Value = 0
.Fields("WH_Waxin").Value = 0
.Fields("WH_Dilut").Value = 0
Else
.Fields("WH_Choke").Value = ews.Cells(j + 8, 4)
.Fields("WH_THP").Value = ews.Cells(j + 8, 5)
.Fields("WH_THT").Value = ews.Cells(j + 8, 6)
.Fields("WH_FLP").Value = ews.Cells(j + 8, 7)
.Fields("WH_FLT").Value = ews.Cells(j + 8, 8)
.Fields("WH_AAnnP").Value = ews.Cells(j + 8, 9)
.Fields("WH_BAnnP").Value = ews.Cells(j + 8, 10)
.Fields("WH_CAnnP").Value = ews.Cells(j + 8, 11)
.Fields("WH_Scale").Value = ews.Cells(j + 8, 12)
.Fields("WH_Corrs").Value = ews.Cells(j + 8, 13)
.Fields("WH_Waxin").Value = ews.Cells(j + 8, 14)
.Fields("WH_Dilut").Value = ews.Cells(j + 8, 15)
End If
.Fields("WH_Commnt").Value = ews.Cells(j + 8, 16)
k=k+1
End If
j=j+1
Loop
.Save
.Close
End With
Next i
MsgBox "Well parameters database to updated to " & ReadToDate
ews.Quit
End If
End Function

You might also like