VBA handler

bradgar

Board Regular
Joined
Aug 29, 2011
Messages
78
trying to have a userform run only once, long story, but for somereason my handler will not take me to the line i specify.

any ideas?

Rich (BB code):
Private Sub coInf1()                
Dim rF$, User$                               
Dim txt As String
 
txt = coInf.Txtbx.Value
User = Application.UserName
rF = ActiveWorkbook.Path & "-" & "8.Log"
 
If Dir(rF) = Empty Then
    coInf.Show
    If txt = "passsword" Then GoTo sLip
    Open rF For Output As #1
    Close #1
    ActiveWorkbook.Save
    MsgBox "Thank You for Registering!" & Chr(13) & Chr(13) & "This Product has now been officially Registered to " & Sheets("INPUT").Cells(2, 8).Value, vbExclamation, "Registration"

End If

sLip:
    Exit Sub

End Sub
seems straight forward enough...
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
What's the value of txt throughout that code?

Does it even get a value here when the userform hasn't been shown yet?
Code:
txt = coInf.Txtbx.Value
Or are you showing the userform then running this code?
 
Upvote 0
Nope that didn't do it, maybe i should make a public value from the userform ?
or do these run in synchronization?
I have a similiar line directly in the usrform OKbutton_click event and it works fine
but this one will not work,

I simply need to skip the code under the handler line if the "password" is entered..
 
Upvote 0
Can you explain the process?

Do you want the user to register if they haven't already?

What about the password, is that always required?

Or is it only non-registered users that require that and once they provide it they get registered so they won't need it next time.
 
Upvote 0
This is for a program I have made for customers. We have had a problem in the past with "sharing" issues. The user form IS the registration and stores the company's name in a locked cell that will never be changed. The program only runs the userform the first time unless myself (or another administrator) enters this password, we can keep the integrity of the 'new' version as we update.

However the pword is not skipping the bottom lines, these bottom lines create a file that if exists will not allow this sub to run due to the first if statement..

Did I explain this well? or was it confusing...?
 
Upvote 0
To be honest I still don't get it.

There's even some stuff that doesn't seem to do anything, or not much anyway.

For example you appear to open a file and then close it again immediately.

Is that just to create the file?
 
Upvote 0
Well, yes just to create the file. However I think you're missing the main point. I only want to know why my handler doesn't skip to the sLip: line...

The sub still runs through the open, close, save and msgbox lines even if i put in pword...
 
Upvote 0
Could it be connected to what I mentioned right at the start?

ie txt is never getting a value

If that's what's happening then txt = "password" will always be false, so the GoTo will never get executed.
 
Upvote 0
I believe it is. I have been trying for another hour now trying to get around that and it seems that there is no way...

FYI opening the file just creates a 0 kb file that if exists will make any
"if dir(...) = empty" line false and therefore not executed...
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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