Macro problem

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
I have 2 command buttons, 1 which opens a userform and enables the user to scroll through the records and amend them, and another which opens the userform but only allows the user to make a new entry.

This is done by enabling/disabling a combobox.

The problem I am having is that I have to seemingly run the macro twice for it to take effect. Any ideas why this might be?

Here are the 2 codes

Editable
Code:
Sub ViewForm()
Dim pword As String
pword = InputBox("Please enter the password:")
If pword <> "mypassword" Then
MsgBox "Incorrect password"
Else
 
UserForm1.Show
 
End If
End Sub


Create New only
Code:
Sub NewForm()
UserForm1.Show
UserForm1.cboAccidentID.Enabled = False
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi Noz,

Which macro do you have to run twice? Both of them?

Have you tried Enabling the combobox in the ViewForm Sub?
 
Upvote 0
Yes both of them.

I have, but the only difference it makes is that when I then close the form it generates an error on that line "cboAccidentID.Enabled = True"

"Run-time error '424':

Object Required"

Edit: Apologies that was because the line should have been UserForm1.cboAccidentID.Enabled = True

So no error now, but still have to run the macros twice
 
Last edited:
Upvote 0
So I had a couple of Me.EnableEvents in my Userform_Initialize which didn't need to be there (I'd left them from something I tried earlier).

So now it works, but strangely the wrong way around where

.Enabled = False, it seems to be enabled

and where

.Enabled = True, it seems to be disabled
 
Upvote 0
Ahh I see now. Swap the cbo enabled line with the userform.show line:

Code:
    Dim pword As String
        pword = InputBox("Please enter the password:")
    If pword <> "a" Then
        MsgBox "Incorrect password"
    Else
        UserForm1.cboAccidentID.Enabled = True
        UserForm1.Show
    End If

Code:
    UserForm1.cboAccidentID.Enabled = False
    UserForm1.Show
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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