URGENT HELP IN A VBA CODE

AYSHANA

Board Regular
Joined
Oct 16, 2021
Messages
90
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
GREAT DAY TO ALL!!

I NEED HELP IN THIS USER FORM
I WANT TO CREAT A FORMULA THAT WILL NOTIFY TO REFILL ALL THE BLANKS WHEN I WILL PRESS (SAVE) IN USER FORM.

THE FOLLOWING IS CODE, THANK YOU.


Private Sub CommandButton1_Click()

Dim TargetRow As Integer
Dim Component As String 'Component


TargetRow = Sheets("ENGINE").Range("B3").Value + 1
Component = TEXT_COMPO

Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 0).Value = TEXT_DEL
Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 1).Value = TEXT_COMPO
Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 2).Value = TEXT_REC
Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 3).Value = TEXT_DATE
Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 4).Value = TEXT_DISP

Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 5).Value = HEMO
Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 6).Value = CLOT
Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 7).Value = BAG
Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 8).Value = LABEL
Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 9).Value = COOLANT
Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 10).Value = SEGMENT
Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 11).Value = TEMP
Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 12).Value = RECBY
Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 13).Value = DATIME

Unload FORM1

MsgBox Component & " was added to the Database", 0, "Complete"



End Sub

Private Sub CommandButton2_Click()

Unload FORM1

End Sub
 

Attachments

  • INSPECTION FORM.PNG
    INSPECTION FORM.PNG
    17.4 KB · Views: 8

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
How to check if all TextBoxes on an Excel UserForm are filled?


VBA Code:
Option Explicit

Public Sub ValidateCheckBoxes()
    Dim EmptyBoxesFound As Boolean

    Dim Ctrl As Control
    For Each Ctrl In Me.Controls
        If TypeName(Ctrl) = "TextBox" Then
            If Ctrl.Text = vbNullString Then
                EmptyBoxesFound = True
                Exit For
            End If
        End If
    Next Ctrl

    If EmptyBoxesFound Then
        MsgBox "At least one box is not filled.", vbExclamation
    Else
        MsgBox "All boxes are filled.", vbInformation
    End If
End Sub
 
Upvote 0
My reading of the initial post was to be able to clear the controls ready for a new record?
Apologies if that was not the case. :(
 
Upvote 0
Perhaps something like this.


VBA Code:
Private Sub CommandButton1_Click()
    
    Dim TargetRow As Integer
    Dim Component As String                           'Component
    Dim MissingData As Boolean
    Dim Ctrl As Control
    
    For Each Ctrl In Me.Controls
        Select Case TypeName(Ctrl)
            Case "TextBox", "ComboBox"
                If Trim(Ctrl.Text) = "" Then
                    MissingData = True
                    Ctrl.BackColor = RGB(255, 255, 153)   'color highlight to indicate missing data
                Else
                    Ctrl.BackColor = vbWhite              'if there is data
                End If
        End Select
    Next Ctrl
    
    If MissingData Then
        MsgBox "Please fill highlighted empty boxes before saving", vbExclamation
        Exit Sub
    End If
    
        TargetRow = Sheets("ENGINE").Range("B3").Value + 1
        Component = TEXT_COMPO
    
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 0).Value = TEXT_DEL
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 1).Value = TEXT_COMPO
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 2).Value = TEXT_REC
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 3).Value = TEXT_DATE
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 4).Value = TEXT_DISP
    
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 5).Value = HEMO
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 6).Value = CLOT
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 7).Value = BAG
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 8).Value = Label
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 9).Value = COOLANT
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 10).Value = SEGMENT
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 11).Value = TEMP
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 12).Value = RECBY
        Sheets("Database").Range("Delivery_Note").Offset(TargetRow, 13).Value = DATIME
    
        Unload FORM1
    
        MsgBox Component & " was added to the Database", 0, "Complete"

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,366
Members
449,080
Latest member
Armadillos

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