When you start the userform the workbook is open. So what i did was close the file when the userform pops up.
Like this:
Private Sub UserForm_Initialize()
Dim wb As Workbook
wb.Close True
Application.ScreenUpdating = True
With Application
.WindowState = xlMaximized
Zoom = Int(.Width / Me.Width * 85)
Width = .Width
Height = .Height
End With
End Sub
Then my idea was to open the file everytime someon pushes a button. For instance the OK button. Then what i want it to do is , open it do whatever is asked ( eg : match number in column with combobox value then put value there ) How i thought of opening it like this:
Private Sub Comboboxx1_Change()
Dim wb As Workbook
Application.ScreenUpdating = False
Set wb = Workbooks.Open("Z:\VBA gekloot\Userform\Voortgangproduktiestart.xls")
With wb.Worksheets("MAIN")
Dim Boot As Double
Dim Boot2 As Integer
Boot = Comboboxx1
Row_Num = WorksheetFunction.Match(Boot, wb.Worksheets("MAIN").Range("D:D"), 0)
Boot2 = 31
Col = Boot2
Label6.Caption = (wb.Worksheets("MAIN").Cells(Row_Num, Col).Value)
Dim Rex As Double
Dim Rex1 As Integer
Rex = Comboboxx1
Row_Num1 = WorksheetFunction.Match(Rex, wb.Worksheets("MAIN").Range("D:D"), 0)
Rex1 = 32
Label7.Caption = (wb.Worksheets("MAIN").Cells(Row_Num1, Rex1).Value)
wb.Close True
Application.ScreenUpdating = True
End With
And exactly the same for the OK button.
Private Sub CommandButton1_Click()
Dim wb As Workbook
Application.ScreenUpdating = False
Set wb = Workbooks.Open("Z:\VBA gekloot\Userform\Voortgangproduktiestart.xls")
With wb.Worksheets("MAIN")
If Not IsNumeric(TextBoxx1.Text) Then
TextBoxx1.Text = ""
MsgBox " Alleen cijfers invullen bij aantalstuks.", vbInformation
Else
Dim Steven2 As String
Dim Steven As Double
Dim Steven4 As String
Dim Steven5 As String
Steven = Comboboxx1
Steven2 = ComboBoxx2
Steven3 = TextBoxx1
Steven4 = ComboBoxx3
Steven5 = Round((Steven3 / Label6.Caption), 2)
Col = WorksheetFunction.Match(Steven2, wb.Worksheets("MAIN").Range("3:3"), 0)
Row_Num = WorksheetFunction.Match(Steven, wb.Worksheets("MAIN").Range("D:D"), 0)
If wb.Worksheets("MAIN").Cells(Row_Num, Col) > 0 Then MsgBox ("Er is al een aantalstuks ingevuld voor Ordernummer " + Comboboxx1 + " en de ploeg van " + ComboBoxx2)
If wb.Worksheets("MAIN").Cells(Row_Num, Col) = "" Then
Dim YesOrNoAnswerToMessageBox As String
YesOrNoAnswerToMessageBox = MsgBox("Je hebt de volgende data ingevoerd Ordernummer:" + Comboboxx1 + " Dienst: " + ComboBoxx2 + " en aantal stuks " + Steven3 + " is deze data correct?", vbYesNo, "Controle")
If YesOrNoAnswerToMessageBox = vbNo Then MsgBox (" De opdracht is gecancelled vul opnieuw de gegevens in.")
If YesOrNoAnswerToMessageBox = vbYes Then
Dim OKAnswerToMessageBox As String
OKAnswerToMessageBox = MsgBox("De data is toegevoegd.")
If OKAnswerToMessageBox = vbOK Then wb.Worksheets("MAIN").Cells(Row_Num, Col) = Steven3
wb.Worksheets("Ronnie controle").Cells(Row_Num, Col) = (Steven3 & " " & ComboBoxx3 & " " & Steven5 & " " & "Uur")
End If
End If
End If
wb.Close True
Application.ScreenUpdating = True
End With
End Sub
But now i get an error:
Runtime error '91'
Object variable or with block variable not set
Any suggestions what migth cause the problem?
Yours , Steven
Bookmarks