Hi,
I have a spreadsheet that contains a macro which has been used for over a year with no issues. The spreadsheet is used by employees in my company to book or cancel desk bookings in our office for chosen days.
However, in the past month some users have started to get a Run-time error '91' (Object variable or With block variable not set). Some users aren't getting it at all, some users get it all the time and for others it can be intermittent. For me personally, I had a couple of weeks just passed where I didn't get the issue at all but suddenly its started happening for me again.
I have a button called 'Book a Desk' that calls a macro to simply opens and initializes a UserForm. I've underlined the part that its failing on (NameTextBoxBook.Value). The TextBox on the UserForm is correctly named (NameTextBoxBook)- see attached. The point its failing on is very simple, its just setting a TextBox Value to be blank when the form loads.
Private Sub UserForm_Initialize()
Dim cDesk As Range
Dim ws As Worksheet
Set ws = Worksheets("Data")
'Opens the booking form in the middle of the screen
Me.StartUpPosition = 0
Me.Left = Application.Left + (0.5 * Application.Width) - (0.5 * Me.Width)
Me.Top = Application.Top + (0.5 * Application.Height) - (0.5 * Me.Height)
'Sets the default values for Name (Blank), Desk Number (Blank) and Date (Cell C6)
NameTextBoxBook.Value = ""
DeskNumberTextBox.Value = ""
DateTextBox.Value = Format(Range("C6").Value, "dd/mm/yyyy")
'Pre-populates the Desk Number list from the tab called 'Data' which is hidden
For Each cDesk In ws.Range("DeskNumber")
With Me.DeskNumberTextBox
.AddItem cDesk.Value
End With
Next cDesk
End Sub
I don't think the issue I'm seeing is specific to this workbook. I tried building a completely new workbook that just loaded a UserForm with a blank TextBox and had the same issue.
Could it be linked to Windows Update or missing Library/Reference or something? Its strange how it has only recently started happening and there have not been any changes to the code in about year...and also strange how it works fine for some user and others its just started happening for.
Help!
Thank you
Bookmarks