Not saving from User form to Workheet

Emancy22

New Member
Joined
May 30, 2017
Messages
11
Whenever I push "Save Donation" I an getting a Run-Time error '1004': Application-defined or object-defined error. I have looked over the code as well as go one by one through the text boxes to see if there was a mismatch in spelling or location. It references the sheet I am asking it to prior to saving it to pick the next row to save it too. I just don't know what to try next. I have highlighted in red where the error occurs and I removed that line during troubleshooting and the error just moves to the end line down. Any ideas? Hopefully I am just overlooking something small! Thanks in Advance! :)

Code:
Private Sub SaveDonation_Click()

SaveBasedOnDonerID
AddData


End Sub


Sub SaveBasedOnDonerID()
 
    Dim Text As String
    
rowCounter = 1
DonorIDSaveColumn = 2
DateColumn = 3
TimeColumn = 4
ProcedureTypeColumn = 5
DonationSiteColumn = 6
DonorEmailColumn = 7
AddToDNCColumn = 8
DispositionColumn = 9
AgentIDColumn = 10
    
    Do
        DonorIDSaveText = ThisWorkbook.Sheets("Donation Info").Cells(rowCounter, DonorIDSaveColumn).Value
        If DonorIDSaveText <> "" Then
            rowCounter = rowCounter + 1
                ThisWorkbook.Sheets("Donation Info").Activate
                Range("A2").Select
        ' Changing loopercell
    ActiveCell.FormulaR1C1 = rowCounter
    End If
    Loop While DonorIDSaveText <> ""
      
End Sub
Function ValidateData() As Boolean
    Dim Proceed As Boolean
    Proceed = True
    
    If DonorIDSave2TextBox.Value = "" Then
        MsgBox "Please copy and paste Donor ID"
        Proceed = False
    End If
    
    If Disposition2TextBox.Value = "" Then
        MsgBox "Please Select a Disposition"
        Proceed = False
    End If
    
    If AgentID2TextBox.Value = "" Then
        MsgBox "Please fill in your Agent ID"
        Proceed = False
    End If
    
    ValidateData = Proceed
 End Function


Sub AddData()


DonorIDSaveColumn = 2
DateColumn = 3
TimeColumn = 4
ProcedureTypeColumn = 5
DonationSiteColumn = 6
DonorEmailColumn = 7
AddToDNCColumn = 8
DispositionColumn = 9
AgentIDColumn = 10


    Dim Proceed As Boolean
    
    Proceed = ValidateData
    
    If Proceed = True Then
   
[COLOR=#ff0000]        ThisWorkbook.Sheets("Donation Info").Cells(rowCounter, DonorIDSaveColumn).Value = DonorIDSave2TextBox.Value[/COLOR]
        ThisWorkbook.Sheets("Donation Info").Cells(rowCounter, DateColumn).Value = Date2TextBox.Value
        ThisWorkbook.Sheets("Donation Info").Cells(rowCounter, TimeColumn).Value = Time2TextBox.Value
        ThisWorkbook.Sheets("Donation Info").Cells(rowCounter, ProcedureTypeColumn).Value = ProcedureType2TextBox.Value
        ThisWorkbook.Sheets("Donation Info").Cells(rowCounter, DonationSiteColumn).Value = donationsite2TextBox.Value
        ThisWorkbook.Sheets("Donation Info").Cells(rowCounter, DonorEmailColumn).Value = DonorEmail2TextBox.Value
        ThisWorkbook.Sheets("Donation Info").Cells(rowCounter, DispositionColumn).Value = Disposition2TextBox.Value
        ThisWorkbook.Sheets("Donation Info").Cells(rowCounter, AgentIDColumn).Value = AgentID2TextBox.Value
        
    End If
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
When I go through this line by line with F8 I am not getting any errors, only when I run it with F5 and put in the data. If that helps narrow down the issue.
 
Upvote 0
I posted this last Monday and still haven't been able to work it out no matter what I change or try, it works all the way through until this same point. If anyone has any idea or suggestions I'd REALLY appreciate it. :(:confused:
 
Upvote 0
Hi,
you have not declared a number of your variables with their data types. I suspect your problem arises because variable RowCounter is empty.

Place the following line of code at the very TOP of your forms code page OUTSIDE of any procedure:

Code:
Dim RowCounter As Long

Hopefully, this will resolve the issue you have highlighted.

You should also declare your other variables in each procedure.

Dave
 
Upvote 0
OMG.... Thank you so much!!! That worked!!!

Glad suggestion resolved for you.

You should be able to tidy up your AddData code without need for all those variables

Untested but one approach could be as follows:
Code:
Sub AddData()


    If Not ValidateData Then Exit Sub
    
    With ThisWorkbook.Sheets("Donation Info")
        .Cells(RowCounter, 2).Value = DonorIDSave2TextBox.Value
        .Cells(RowCounter, 3).Value = Date2TextBox.Value
        .Cells(RowCounter, 4).Value = Time2TextBox.Value
        .Cells(RowCounter, 5).Value = ProcedureType2TextBox.Value
        .Cells(RowCounter, 6).Value = donationsite2TextBox.Value
        .Cells(RowCounter, 7).Value = DonorEmail2TextBox.Value
        .Cells(RowCounter, 9).Value = Disposition2TextBox.Value
        .Cells(RowCounter, 10).Value = AgentID2TextBox.Value
    End With


End Sub



Dave
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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