Gruppe
Dialog
Problem
Über die Tastenkombination Strg+a wird ein Dialog aufgerufen. Wenn sich der Cursor in einer Produktzeile (Zeile 2 oder 3) befindet, werden die Produktdaten aus der Datenbank eingelesen.
StandardModule: Modul1
Sub DialogAufruf()
frmProdukte.Show
End Sub
ClassModule: frmProdukte
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim iCol As Integer, iCounter As Integer
Dim sLabel As String
For iCounter = 1 To 4
If Controls("Label" & iCounter).Visible Then
sLabel = Controls("Label" & iCounter).Caption
sLabel = Left(sLabel, Len(sLabel) - 1)
Cells(ActiveCell.Row, iCounter * 2).Value = Controls("TextBox" & iCounter).Text
Cells(ActiveCell.Row, (iCounter * 2) + 1).Value = sLabel
End If
Next iCounter
End Sub
Private Sub UserForm_Initialize()
Dim var As Variant
Dim iCounter As Integer, iColL As Integer
var = Application.Match(Cells(ActiveCell.Row, 1).Value, wksData.Columns(1), 0)
If Not IsError(var) Then
iColL = ((WorksheetFunction.CountA(wksData.Rows(var)) - 1) / 2)
For iCounter = 1 To iColL
With Controls("Label" & iCounter)
.Visible = True
.Caption = wksData.Cells(var, (iCounter * 2) + 1).Value & ":"
End With
With Controls("TextBox" & iCounter)
.Visible = True
.Text = wksData.Cells(var, (iCounter * 2)).Value
End With
Next iCounter
End If
End Sub