Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-11-2005, 11:05 AM   #1 (permalink)
Broken In
 
Join Date: Aug 2004
Posts: 101
Default passwor protecting command buttons in VB


i'm want to create a program in vb which will allow two sorts of entry..as a regular user and as a privilaged user.to enter as i privilaged user, u will hv to supply a password. the program i'm developing is a data driven program and the only advantage that a privilaged user gets is the ability to modify the database.
i was thinking of making two forms..the entry form with two radio buttons for the two types of users.selecting the privilaged user wil prompt for the password which when entered correctly will display the actual form with all the command buttons enabled.if the password is wrong or the normal user is selected..the buttons that are for modifying the database will be invisible.
i have made the second,ie the data access form..complete with the command buttons and everything.but i'm getting muddled with the logging in part.
it would be very helpful if some of u geeks could help me with the code of that part.
thanks...
geekgod is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 12-11-2005, 11:39 AM   #2 (permalink)
Wise Old Owl
 
siriusb's Avatar
 
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
Default

Since you are having only two types of users (root and normal), declare a public boolean named root in the second form. If the login form validates the user as a root, then make it to set this public variable to true and then unload the login form. In the second form's load event, make visible/invisible the controls based on this root boolean.
Is this what you were in doubt?
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
siriusb is offline  
Old 14-11-2005, 08:27 AM   #3 (permalink)
Broken In
 
Join Date: Aug 2004
Posts: 101
Default

ya..something like that..
now i am facing another problem
i created two forms before the original form..a selectuser for with two radio buttons for selecting the user types, and a login form to validate the administrator.
the selectuser form had the following code
Code:
Private Sub cmdok_Click()

If op1.Value = True Then
    usertype = False    'select normal user
ElseIf opt2.Value = True Then
    Call Load(frmLogin)
    Call frmLogin.Show
    If LoginSucceeded = True Then
    usertype = True
    Else
    usertype = False
    End If
End If
Call Load(frmview)
Call frmview.Show
Unload Me
End Sub
here's the screenshot


the loginform was programmed thus
Code:
Private Sub cmdCancel_Click()
        LoginSucceeded = False
    Me.Hide
    
End Sub

Private Sub cmdok_Click()
   
    If txtPassword = "password" Then
       LoginSucceeded = True
        Me.Hide
    Else
        MsgBox "Invalid Password, try again!", , "Login"
        txtPassword.SetFocus
        SendKeys "{Home}+{End}"
    End If
End Sub

Private Sub Form_Load()

End Sub
i declared the two public variables LoginSucceeded and usertype as boolean in a separate module

finally, i included the following snippet in the needed portions of the main fom
Code:
Public Sub checkuser()
If usertype = False Then
Command2(4).Visible = False
Command2(5).Visible = False
Command2(6).Visible = False
Command2(7).Visible = False
End If
End Sub
now th problem is..whenever i run the program without the option of logging in,ie i directly go into the program as a particular type of user without validation,it is running fine.
but when i include the option of logging in..whichever type of user i select,the program always starts in the normal user mode..
what do u think is the problem?


----------------------------------------------------------------------------
geekgod is offline  
Old 14-11-2005, 08:37 AM   #4 (permalink)
Broken In
 
Join Date: Aug 2004
Posts: 101
Default

there is another problem...
the program i created requires me to search from a database and display the results.for this i added a separate find for where i included an API call to display the available records as i type.
heres the code....

this is the API call..
Code:
Public Declare Function sendMessageByStrings& Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
                      ByVal lParam As String)
Public Const LB_SELECTSTRING = &H18C
Public gFindString As String
[quote]Public Const gDataBaseName = "C:\Documents and Settings\Apollo\My Documents\New Folder (2)\db12.mdb"
this is the code for the find form
Code:
Private Sub Form_Activate()
List1.Enabled = False
dtafind.DatabaseName = gDataBaseName
dtafind.Refresh
If (dtafind.Recordset.RecordCount > 0) Then
    Screen.MousePointer = vbHourglass
    dtafind.Recordset.MoveFirst
    While Not dtafind.Recordset.EOF
        List1.AddItem dtafind.Recordset.Fields(0) & ""
        dtafind.Recordset.MoveNext
    Wend
    List1.Enabled = True
    DoEvents
End If
lblcount = "There are " & dtafind.Recordset.RecordCount & " records"
Screen.MousePointer = vbDefault

End Sub

Public Property Let recordsource(ByVal sNewValue As String)
dtafind.recordsource = sNewValue
End Property

Private Sub Form_Unload(Cancel As Integer)
Set frmfind = Nothing
End Sub

Private Sub List1_DblClick()
gFindString = List1
Unload frmfind

End Sub

Private Sub txtfind_Change()
Dim entryNum As Long
Dim txttofind As String
txttofind = txtfind.Text
entryNum = sendMessageByStrings(List1.hwnd, LB_SELECTSTRING, 0, txttofind)

End Sub
and this is the code for linking the find form with the main program..this code is the event of clicking the "Find" button

Code:
Case cmdfind
Dim ireturn As Integer
gFindString = ""
With frmfind
    .recordsource = "SELECT term FROM Table1 ORDER BY term"
    .Show vbModal
End With
If (Len(gFindString) > 0) Then
    With Data1.Recordset
        .FindFirst "term = '" & gFindString & "' "
            If (.NoMatch) Then
                ireturn = MsgBox("term " & gFindString & _
                                 " was not found.", vbCritical, "term")
            Else
                ireturn = MsgBox("term " & gFindString & " was retrieved.", _
                              vbInformation, "term")
            End If
    End With
End If
now the problem is..when i run the program from within vb..it runs fine..
but when i make the .exe and run it..the search part does not work.the API call and the find form responds just fine..it even says "the ' ' term was retrieved" as i had instructed i to say..but the record that is returned by the find form is not displayed in the main form


another questoin...how do i make the loacation of the database as indicated in the code independant of where the setup file install the program..i mean..here i have given the location of gDataBasename as
Quote:
Public Const gDataBaseName = "C:\Documents and Settings\Apollo\My Documents\New Folder (2)\db12.mdb"
but the user may not install the program in that manner...in fact there is little chance he will.so how what code do i need to include or modify to make this program run?

i know this was a very long post..thanks for bearing with it..
waiting for ur replies..
geekgod is offline  
Old 15-11-2005, 12:53 PM   #5 (permalink)
Broken In
 
Join Date: Aug 2004
Posts: 101
Default

cmon guys...help me on this.i really need to make this work....
geekgod is offline  
Old 15-11-2005, 02:08 PM   #6 (permalink)
Wise Old Owl
 
siriusb's Avatar
 
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
Default

For your first problem, you need to call the login form (where you enter the password) like so:
Code:
Call frmLogin.Show(1, Me)
THis will make the if statement to wait till the login form is dismissed before rushing on to execute the next statements. That's the difference between modal and modeless forms.
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
siriusb is offline  
Old 15-11-2005, 11:05 PM   #7 (permalink)
Broken In
 
Join Date: Aug 2004
Posts: 101
Default

thnks frnd..one of my problems solved now..
waiting for the other to be solved too...

nd just for curiosity..@siriusb..how long have you been programming with vb?
geekgod is offline  
Old 16-11-2005, 07:33 PM   #8 (permalink)
Wise Old Owl
 
siriusb's Avatar
 
Join Date: May 2005
Location: Chennai, India, Asia, the Earth, the Solar system, the Milky Way, the Local group, this Universe.
Posts: 1,171
Default

I have no idea of the second problem. Hope you were able to solve it by now.
And storing absolute paths is a bad practice. You should always try to use relative paths or dynamic ones (like $windir or something). You cannot know where an mdb database would be stored. Your best bet is to search for commonly used paths (c:\, d:\, ...) or ask the user to "setup" your program or use a DSN.

I learnt most of the stuff when I was in 12th std. Now I don't use VB at all.
__________________
http://myxp.blogspot.com
-----------------------
Winchester 3200+ @2,500MHz
LeadTek 7900GT VOLT MODDED @ 680 core, 1800 mem
2x1GB Transcend DDR400 @ DDR454 2.5,3,3,5,1T
siriusb is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by clmlbx
- by gforz
- by Who

Advertisement




All times are GMT +5.5. The time now is 04:50 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2