1

I am creating a yard management system to keep track of parking spots in a lot.

The userform allows the user to click on a spot in the map (this would be the command button) that is open and then click update which will pull up another userform to fill out information about the truck going to that spot.

Once a user fills in the second userform, the spot changes from green to red to show that it is filled. Right now, there is no way to edit data entered for a spot.

For example, I might need to change the truck status from empty to full.

I think the best way to do this would be

  • if a spot is red (full and has information entered in the userform), then it will automatically pull up the second userform with the data already entered showing, so if something needs to be changed they can just type in the textbox and press update again.
  • if the spot is empty, it should pull up the first userform asking to update or clear the spot.

I am not sure if this is possible or the most efficient way to accomplish my goal of editing the already entered information, without having to fill out the entire userform again.

Private Sub cmdCancel_Click()
    Unload Me
End Sub

Private Sub cmdClear_Click()
    ActiveCell.ClearContents
    ActiveCell.Interior.Color = vbGreen
    Unload Me
End Sub

Private Sub cmdUpdate_Click()
    UpdateInfo.Show
    Unload Me
End Sub

Private Sub CommandButton1_Click()
    UpdateInfo.Show
    Unload Me
End Sub

Private Sub UserForm_Initialize()
    lblInfo = ActiveCell.Value
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Set rngBDock = Range("BX7:CO7")
Set rngBulk = Range("BZ21:CG21")
Set rngTransT = Range("BF17:BY17")
Set rngTransT1 = Range("BG21:BY21")
Set rngTDock = Range("BL7:BW7")
Set rngEDock = Range("CP7:CT7")
Set rngNDock = Range("CU7:DC7")
Set rngFence = Range("CQ13:CV13")
Set rngNSide = Range("CW13:DB13")
Set rngGEO = Range("BG28:DD28")
Set rngNight = Range("CH21:DD21")
Set rngNewT = Range("DK31:DK65")
Set rngNewTl = Range("DI31:DI65")
Set rngOff = Range("BN40:CL40")
Set rngOffl = Range("BN42:CL42")
Set rng = Union(rngBDock, rngBulk, rngTransT, rngTransT1, rngTDock, rngEDock, rngNDock, rngFence, rngNSide, rngGEO, rngNight, rngNewT, rngNewTl, rngOff, rngOffl)

If Not Intersect(Target, rng) Is Nothing Then
    CellInfo.Show
    'ActiveCell.Value = cellFill
    If Not IsEmpty(ActiveCell.Value) Then
        Call RealTimeTracker
    End If
End If
Private Sub cmdOkUpdate_Click()

Dim i As Integer, j As Integer

For i = 0 To lbxOption.ListCount - 1
    If lbxOption.Selected(i) Then j = j + 1
Next i
If j = 0 Then
    MsgBox "Please select an option. ", , "Warning"
    Unload Me
    UpdateInfo.Show
ElseIf j = 1 Then
    NoFill = False
End If

strBOL = txtBOL.Value
strID = txtID.Value
details = txtDet.Value
opt = lbxOption.Value
currtime = time()
today = Format(Now(), "MM/DD/YYYY")
emp = TextBox1.Value

With ActiveCell
    spot = .Offset(-1, 0)
    If Len(spot) = 0 Then
        spot = .Offset(1, 0)
    Else
        spot = spot
    End If
End With

If NoFill = True Then
    cellFill = ""
ElseIf NoFill = False Then
    With Sheet5
        .Range("A1").Value = "Time"
        .Range("B1").Value = "Date"
        .Range("C1").Value = "Location"
        .Range("D1").Value = "Category"
        .Range("E1").Value = "BOL"
        .Range("f1").Value = "Trailer #"
        .Range("g1").Value = "Details"
        .Range("H1").Value = "EE Name"
    
        .Range("A2").EntireRow.Insert
        .Range("A2").Value = currtime
        .Range("B2").Value = today
        .Range("C2").Value = spot
        .Range("D2").Value = opt
        .Range("E2").Value = strBOL
        .Range("F2").Value = strID
        .Range("G2").Value = details
        .Range("H2").Value = emp
    
        .Columns("A:H").AutoFit
    End With

    If Not IsEmpty(opt) Then
        cellFill = opt & " " & vbCrLf & "BOL (last 5 digits): " & strBOL & " " & vbCrLf & "Trailer # " & strID & " " & vbCrLf & details & "EE Name" & emp & " " & vbCrLf
        ActiveCell.Value = cellFill
        Call RealTimeTracker
    End If
    
End If

Unload Me
Sheet1.Activate

End Sub
Community
  • 1
  • 1
Leah
  • 31
  • 1
  • 7
  • Yes, the approach you describe is very doable. You will need an If statement to check the color of the clicked button and then additional code to fill in the user form before showing it. – Brian M Stafford Aug 31 '20 at 14:14
  • Thank you! Could you please give some guidance or example as to what that additional code would be? I have the if statement in there. – Leah Aug 31 '20 at 15:26

0 Answers0