User form for customer entry

kamranyd

Board Regular
Joined
Apr 24, 2018
Messages
152
Office Version
  1. 2021
Platform
  1. Windows
I have these codes which work fine for copying customer info to database, but i need it copy only customer name to database nothing else.

VBA Code:
Private Sub SaveBtn_Click()
Dim CustomerFld As Control
Dim CustRow As Long, CustCol As Long
If Me.Field1.Value = Empty Then
    MsgBox "Please make sure to save a Customer Name before saving", vbCritical
    Exit Sub
End If
With Customers
    If Invoice.Range("B1").Value = Empty Then 'New Customer
        CustRow = .Range("A99999").End(xlUp).Row + 1 'First avail Row
    Else
        CustRow = Invoice.Range("B3").Value
    End If
    For CustCol = 2 To 8
        Set CustomerFld = Me.Controls("Field" & CustCol - 1)
            .Cells(CustRow, CustCol).Value = CustomerFld.Value
    Next CustCol
    AddCustForm.Hide
    Invoice.Range("B1").Value = Field1.Value 'Set Customer Name
End With
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Probably
VBA Code:
Private Sub SaveBtn_Click()
    Dim CustRow As Long
    
    If Me.Field1.Value = Empty Then
        MsgBox "Please make sure to save a Customer Name before saving", vbCritical
        Exit Sub
    End If
    
    With Customers
        If IsEmpty(Invoice.Range("B1").Value) Then    'New Customer
            CustRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1   'First avail Row
        Else
            CustRow = Invoice.Range("B3").Value
        End If
        
        .Cells(CustRow, "B").Value = Me.Field1.Value
    End With
        
        AddCustForm.Hide
        Invoice.Range("B1").Value = Field1.Value    'Set Customer Name
End Sub
Artik
 
Upvote 1
Probably
VBA Code:
Private Sub SaveBtn_Click()
    Dim CustRow As Long
   
    If Me.Field1.Value = Empty Then
        MsgBox "Please make sure to save a Customer Name before saving", vbCritical
        Exit Sub
    End If
   
    With Customers
        If IsEmpty(Invoice.Range("B1").Value) Then    'New Customer
            CustRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1   'First avail Row
        Else
            CustRow = Invoice.Range("B3").Value
        End If
       
        .Cells(CustRow, "B").Value = Me.Field1.Value
    End With
       
        AddCustForm.Hide
        Invoice.Range("B1").Value = Field1.Value    'Set Customer Name
End Sub
Artik
thnx artik, now i merge my cell B1 with C1 now it give me error like run time error 424 "object required". may be because i merge cell is there any solution to that other unmerge cell
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,171
Members
452,615
Latest member
bogeys2birdies

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