sathyaganapathi
Board Regular
- Joined
- Apr 29, 2021
- Messages
- 81
- Office Version
- 2016
- Platform
- Windows
Hello, I have excel vba macro to update access table. this works in one PC, but, crashes in other PC. the configuration of PC is same. could anybody please help?
VBA Code:
Private Sub LabUpdate_Click()
If Me.Department.value = "" Then
MsgBox "Select a record from List to update"
Call LabClear_Click
Exit Sub
End If
If Me.ComplDate.value = "" Then
Me.ComplDate.BackColor = vbRed
MsgBox "Enter Date", vbCritical
Exit Sub
End If
If Me.LabEmp.value = "" Then
Me.LabEmp.BackColor = vbRed
MsgBox "Please enter Employee name", vbCritical
Exit Sub
End If
Sheets("Ctables").Range("u3").value = Me.ComplDate.value
'''''''''''''''''''''''''''''''''''''''''
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim qry As String
Dim Source As String
Source = Me.Source.value
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Source
If Me.txtId.value <> "" Then
qry = "SELECT * FROM TBL_ClabInput WHERE ID = " & Me.txtId.value
Else
qry = "SELECT * FROM TBL_ClabInput Where ID = 0"
End If
rst.Open qry, cnn, adOpenKeyset, adLockOptimistic
If rst.RecordCount = 0 Then
rst.AddNew
End If
rst.Fields("CompletedTime").value = CDate(Me.ComplDate.value)
rst.Fields("AnalysisBy").value = Me.LabEmp.value
rst.Fields("Lab_Remarks").value = Me.LabRmrks.value
rst.Fields("TimeToComplete").value = Me.TimeToCmplt.value 'VBA.Format(Val(Me.ComplDate.Value) - Val(Me.txtDate.Value), "HH:mm")
rst.Fields("Comp_Shift").value = Sheets("Ctables").Range("v3").value
' rst.Fields("BlankHourSamples").value = Sheets("Ctables").Range("v4").value
rst.Update
rst.Close
cnn.Close
Call ClearAll_Click
Sheets("Ctables").Range("u3").value = ""
ArchiveDbFile
MsgBox "Updated Successfully", vbInformation
Call List_box_Data
End Sub