When I run the following userform code, it will run once. After that I receive a Run-Time error '-2147417848 (80010108)': Method 'Value' of object 'Range' failed.
After clicking end on the prompt, Excel locks up and I have to end the process. Upon opening the document, the data for the second row is not there and the formatting is incorrect on the newly added row. Please not that the row of data is part of a table.
Additionally, if I attempt to delete the row of data that applies to the worksheet, Excel crashes with the following Event Viewer information. This only happens immediately after running the code. If I exit the workbook there isn't an issue.
Event viewer log for both issues is similar.
Faulting application name: EXCEL.EXE, version: 14.0.4756.1000, time stamp: 0x4b9c08e8
Faulting module name: EXCEL.EXE, version: 14.0.4756.1000, time stamp: 0x4b9c08e8
Exception code: 0xc0000005
Fault offset: 0x00127de8
Faulting process id: 0x1418
Faulting application start time: 0x01cbe80a04c19164
Faulting application path: C:\Program Files\Microsoft Office\Office14\EXCEL.EXE
Faulting module path: C:\Program Files\Microsoft Office\Office14\EXCEL.EXE
Report Id: 5352e940-53fd-11e0-8a15-f0def126af42
This works fine in Excel 2007, but not in Excel 2010.
I've looked over my code and I'm sure I am missing something with the switch to a newer VBA in Excel 2010, but I'm not sure what it is.
The first block of code runs on command button click and calls the second block of code to apply the data on the userform.
Any help with the code or with this specific issue would be greatly appreciated as I am trying to move from Excel 2007 to 2010.
After clicking end on the prompt, Excel locks up and I have to end the process. Upon opening the document, the data for the second row is not there and the formatting is incorrect on the newly added row. Please not that the row of data is part of a table.
Additionally, if I attempt to delete the row of data that applies to the worksheet, Excel crashes with the following Event Viewer information. This only happens immediately after running the code. If I exit the workbook there isn't an issue.
Event viewer log for both issues is similar.
Faulting application name: EXCEL.EXE, version: 14.0.4756.1000, time stamp: 0x4b9c08e8
Faulting module name: EXCEL.EXE, version: 14.0.4756.1000, time stamp: 0x4b9c08e8
Exception code: 0xc0000005
Fault offset: 0x00127de8
Faulting process id: 0x1418
Faulting application start time: 0x01cbe80a04c19164
Faulting application path: C:\Program Files\Microsoft Office\Office14\EXCEL.EXE
Faulting module path: C:\Program Files\Microsoft Office\Office14\EXCEL.EXE
Report Id: 5352e940-53fd-11e0-8a15-f0def126af42
This works fine in Excel 2007, but not in Excel 2010.
I've looked over my code and I'm sure I am missing something with the switch to a newer VBA in Excel 2010, but I'm not sure what it is.
The first block of code runs on command button click and calls the second block of code to apply the data on the userform.
Code:
Private Sub cmdAdd_Click()
'Set lSheet value based on Checkbox status | call Apply_Record, pass lSheet variable
Dim lSheet As Worksheet
If cbxChecking.Value = "True" Then
Set lSheet = Worksheets("Checking")
Call Apply_Record$(lSheet)
ElseIf cbxChecking.Value = "False" Then
Set lSheet = Worksheets("Savings")
Call Apply_Record$(lSheet)
End If
frmMain.lstData.RowSource = "CheckingData"
frmMain.lstData.Selected(lstData.ListCount - 1) = True
End Sub
Code:
Public Sub Apply_Record(iSheet)
Dim iRow As Long, ws As Worksheet
'set passed variable to ws variabe
Set ws = iSheet
'find first empty row in database
If frmMain.cbxFirst.Value = "True" Then
iRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
Else
iRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
End If
'check for a date
If Trim(frmMain.txtDate.Value) = "" Then
MsgBox "Please enter a date"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 2).Value = frmMain.txtDate.Value
ws.Cells(iRow, 3).Value = frmMain.cbVenue.Value
ws.Cells(iRow, 4).Value = frmMain.cbDesc.Value
ws.Cells(iRow, 5).Value = frmMain.cbType.Value
ws.Cells(iRow, 6).Value = frmMain.txtDepo.Value
ws.Cells(iRow, 7).Value = frmMain.txtWith.Value
ws.Cells(iRow, 9).Value = frmMain.cbVeri.Value
'clear the data from userform
frmMain.txtDate.Value = ""
frmMain.cbVenue.Value = ""
frmMain.cbDesc.Value = ""
frmMain.cbType.Value = ""
frmMain.txtDepo.Value = ""
frmMain.txtWith.Value = ""
frmMain.cbVeri.Value = ""
'Set focus to close button
frmMain.cmdClose.SetFocus
'Form Analysis Refresh
Call SumLoop_Apply
'Refresh Venues to see new data entries in userform
If frmMain.cbxChecking.Value = "True" Then
frmMain.cbDesc.RowSource = "CheckDesc"
ElseIf frmMain.cbxChecking.Value = "False" Then
frmMain.cbDesc.RowSource = "SavDesc"
End If
End Sub
Any help with the code or with this specific issue would be greatly appreciated as I am trying to move from Excel 2007 to 2010.