UserForm Data Output to Table (formatted as table)

Printmark

New Member
Joined
Jan 22, 2010
Messages
7
I'm having problems figuring out how to output userform data in excel to an excel table that is formatted as a table.

Is there a way to "add existing fields" to the userform like you can do in Access.

It is just a simple contact database (company name, contact, address...)

Here is the code I am trying, but it never reaches the table as I don't have the table defined... not sure how to specify the table (called Table_Customer_Contact_DB)

Code:
Private Sub btnSaveAndReturn_Click()
    Dim i, j As Integer
    Dim varCustomer As Variant
    Dim varContact As Variant
    Dim varStreet1 As Variant
    Dim varStreet2 As Variant
    Dim varCity As Variant
    Dim varEmail As Variant
    Me.lblEmail.ForeColor = 0
    Me.lblStreet2.ForeColor = 0
    Me.lblCustomer.ForeColor = 0
    Me.lblContact.ForeColor = 0
    Me.lblStreet1.ForeColor = 0
    Me.lblCity.ForeColor = 0
    varNo = Array("\", "/", ":", "*", "?", """", "<", ">", "|", "'")
    If IsNull(Me.txbCustomer) = False Then
    varCustomer = Me.txbCustomer
    For i = 0 To UBound(varNo)
    j = InStr(1, varCustomer, varNo(i))
    If j > 0 Then
    MsgBox "Cannot use character:" & Chr(13) & Chr(10) & Chr(13) _
    & Chr(10) & varNo(i), vbCritical, " Illegal Character"
    Me.lblCustomer.ForeColor = 255
    Exit Sub
    Exit For
    End If
    Next
    End If
    If IsNull(Me.txbContact) = False Then
    varContact = Me.txbContact
    For i = 0 To UBound(varNo)
    j = InStr(1, varContact, varNo(i))
    If j > 0 Then
    MsgBox "Cannot use character:" & Chr(13) & Chr(10) & Chr(13) _
    & Chr(10) & varNo(i), vbCritical, " Illegal Character"
    Me.lblContact.ForeColor = 255
    Exit Sub
    Exit For
    End If
    Next
    End If
    If IsNull(Me.Street1) = False Then
    varStreet1 = Me.Street1
    For i = 0 To UBound(varNo)
    j = InStr(1, varStreet1, varNo(i))
    If j > 0 Then
    MsgBox "Cannot use character:" & Chr(13) & Chr(10) & Chr(13) _
    & Chr(10) & varNo(i), vbCritical, " Illegal Character"
    Me.lblStreet1.ForeColor = 255
    Exit Sub
    Exit For
    End If
    Next
    End If
    If IsNull(Me.txbStreet2) = False Then
    varStreet2 = Me.txbStreet2
    For i = 0 To UBound(varNo)
    j = InStr(1, varStreet2, varNo(i))
    If j > 0 Then
    MsgBox "Cannot use character:" & Chr(13) & Chr(10) & Chr(13) _
    & Chr(10) & varNo(i), vbCritical, " Illegal Character"
    Me.lblStreet2.ForeColor = 255
    Exit Sub
    Exit For
    End If
    Next
    End If
    If IsNull(Me.txbCity) = False Then
    varCity = Me.txbCity
    For i = 0 To UBound(varNo)
    j = InStr(1, varCity, varNo(i))
    If j > 0 Then
    MsgBox "Cannot use character:" & Chr(13) & Chr(10) & Chr(13) _
    & Chr(10) & varNo(i), vbCritical, " Illegal Character"
    Me.lblCity.ForeColor = 255
    Exit Sub
    Exit For
    End If
    Next
    End If
    If IsNull(Me.txbEmail) = False Then
    varEmail = Me.txbEmail
    For i = 0 To UBound(varNo)
    j = InStr(1, varEmail, varNo(i))
    If j > 0 Then
    MsgBox "Cannot use character:" & Chr(13) & Chr(10) & Chr(13) _
    & Chr(10) & varNo(i), vbCritical, " Illegal Character"
    Me.lblEmail.ForeColor = 255
    Exit Sub
    Exit For
    End If
    Next
    End If
    Unload Me
End Sub

Thanks for any suggestions....
Printmark
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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