excel vba works in one PC, but do not work on other PC

sathyaganapathi

Board Regular
Joined
Apr 29, 2021
Messages
81
Office Version
  1. 2016
Platform
  1. 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
 

Attachments

  • references.jpg
    references.jpg
    47.2 KB · Views: 13

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
What exactly do you mean by "crashes"? Excel actually quits, or you get an error, or something else?
 
Upvote 0
What exactly do you mean by "crashes"? Excel actually quits, or you get an error, or something else?
Hi RoryA,
The excel quits and closes all open excel workbooks. No error is displayed !
The data is not uploaded to access table.
 
Upvote 0
Have you tried stepping through the code to see which line causes the crash?
 
Upvote 0
Have you tried stepping through the code to see which line causes the crash?
Hi RoryA, I am finding difficult in checking the coding by stepping through it. this is the first project I am working with excel 'User forms' and when I try to stepping through the code the 'userform' opens and I could not proceed on it..
 
Upvote 0
Put a breakpoint on the first line of that code and then click whatever LabUpdate is. That will then allow you to step through the code.
 
Upvote 0
Put a breakpoint on the first line of that code and then click whatever LabUpdate is. That will then allow you to step through the code.
Ok.. I will try that and update.... thanks a lot for the quick reply...
 
Upvote 0
Put a breakpoint on the first line of that code and then click whatever LabUpdate is. That will then allow you to step through the code.
Hi RoryA, when I put the breakpoint at below line, it stops there.

VBA Code:
    rst.Fields("Lab_Remarks").value = Me.LabRmrks.value

but, when breakpoint is put on the next line, the excel is quitting without any error..

VBA Code:
    rst.Fields("TimeToComplete").value = Me.TimeToCmplt.value

both the above fields are 'shorttext' field in access table.

As I mentioned in my post, this problem is observed only in one particular PC. works fine in ther PCs. The configuration of PCs are same...
 
Upvote 0
I can't see anything in that code that should cause Excel to crash, I'm afraid.
 
Upvote 0
Are you using or defining the word 'value' anywhere, i was trying to work out why your .value is not .Value all the way through the code. I have seen this before when the word value is used as a variable somewhere in the code.

It's interesting that it fails on the first on that contains an underscore...
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,674
Members
449,463
Latest member
Jojomen56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top