While sheet is protected, allow cmdButton to refresh query.

G

Guest

I have two sections on my sheet. One being a query and the next section for
users to input data. The query is protected and the later can be edited.
However, I would like to allow users to click on an update button which I
have programmed to update the queries from database. When the sheet is
protected, users failed to click on the button eventhough I have uncheck the
lock property.

This is the code for the update button:
Private Sub cmdButton_RefreshMDBF_Click()

Range("MDBF_Query").QueryTable.Refresh BackgroundQuery:=False
Range("Plan_MDBF_Query").QueryTable.Refresh BackgroundQuery:=False
Range("MDBF_Plan").Calculate

End Sub
 
N

Norman Jones

Hi M,

Try:
'===========>>
Private Sub cmdButton_RefreshMDBF_Click()
Dim SH As Worksheet

Set SH = Sheets("Sheet1") '<<==== CHANGE

SH.Unprotrect Password:= "Your password"

'Your query code

SH.Protrect Password:= "Your password"

End Sub
'<<===========
 
G

Guest

Thanks. It worked!

Norman Jones said:
Hi M,

Try:
'===========>>
Private Sub cmdButton_RefreshMDBF_Click()
Dim SH As Worksheet

Set SH = Sheets("Sheet1") '<<==== CHANGE

SH.Unprotrect Password:= "Your password"

'Your query code

SH.Protrect Password:= "Your password"

End Sub
'<<===========
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top