Results 1 to 6 of 6

Thread: [RESOLVED]Can you help me solve my problem ? Thanks you

  1. #1

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    [RESOLVED]Can you help me solve my problem ? Thanks you

    VB Code:
    1. Private Sub cmdLogin_Click()
    2. Dim pStrLoginWhere As String
    3. Dim rSLogin As Recordset
    4. Dim DecryptedPass As String
    5.     Call ValidateEmptyField(frmlogin)
    6.  
    7.             pStrLoginWhere = " WHERE User_ID = '" & txtUname.Text & "'"
    8.            
    9.             Set rSLogin = SQLSELECT("*", "UserControl", pStrLoginWhere, "", "", "Maintenance")
    10.             If Not (rSLogin.BOF = True Or rSLogin.EOF = True) Then
    11.                 DecryptedPass = RndCrypt(rSLogin!Password, "Password")
    12.                     If txtPassword.Text = DecryptedPass Then
    13.                         gstrUserGroup = rSLogin!Position
    14.                         gstrUserID = rSLogin!User_ID
    15.                         Me.Hide
    16.                         MDIMaintenance.Show
    17.                     Else
    18.                         MsgBox "Invalid Password, Please Try again", vbOKOnly, "Invalid Login"
    19.                         Call HighLight(txtPassword)
    20.                     End If
    21.             Else
    22.                 MsgBox "Invalid User Name Login.try again!", vbOKOnly, "Login!!"
    23.                 Call HighLight(txtUname)
    24.             End If
    25. End Sub
    26.  
    27. Public Sub SQLExecute(pstrDBName As String)
    28.    
    29.     Set conn = New ADODB.Connection
    30.    
    31.     conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
    32.     "Persist Security Info=true;" & _
    33.     "Initial Catalog=Maintenance;User Id=;Password=;Data Source=SHLIM\SQLEXPRESS;"
    34.    
    35.     conn.Open
    36. End Sub
    37.  
    38. Public Function SQLSELECT(pstrFIELD As String, pstrTABLE As String, pstrWHERE As String, pstrGROUPBY As String, pstrOrderBy As String, pstrDBName As String) As ADODB.Recordset
    39.     Dim pstrSELECT As String
    40.    
    41.  
    42.     pstrSELECT = " SELECT " & pstrFIELD & " FROM " & pstrTABLE & pstrWHERE & _
    43.         pstrGROUPBY & pstrOrderBy
    44.    
    45.     Call SQLExecute(pstrDBName)
    46. [U][I]    SQLSELECT.Open pstrSELECT, conn, adOpenKeyset, adLockPessimistic, adCmdText [/I][/U]
    47.    
    48. End Function

    Please help me check my code contains any problem because i obtain error of -- > Object variable or with block variable not set.

    Thanks !!!
    Last edited by nUflAvOrS; Sep 18th, 2007 at 04:47 AM.
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  2. #2
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Can you help me solve my problem ? Thanks you

    where have u declared conn?

  3. #3

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: Can you help me solve my problem ? Thanks you

    Sorry Sir,
    i had declared it in my project
    i forgot to attach it together
    VB Code:
    1. Private conn as ADODB.Connection
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  4. #4
    Addicted Member
    Join Date
    Aug 2007
    Location
    India
    Posts
    141

    Re: Can you help me solve my problem ? Thanks you

    In your code the function SQLSELECT return the recordset.

    You need to declare one local recordset and then open it and return it as the function value

    vb Code:
    1. Public Function SQLSELECT(pstrFIELD As String, pstrTABLE As String, pstrWHERE As String, pstrGROUPBY As String, pstrOrderBy As String, pstrDBName As String) As ADODB.Recordset
    2.  
    3.     Dim pstrSELECT As String
    4.     pstrSELECT = " SELECT " & pstrFIELD & " FROM " & pstrTABLE & pstrWHERE & _
    5.     pstrGROUPBY & pstrOrderBy
    6.     Call SQLExecute(pstrDBName)
    7.      Dim x as ADODB.RECORDSET
    8.      SET x=new ADODB.RECORDSET
    9.      x.Open pstrSELECT, conn, adOpenKeyset, adLockPessimistic, adCmdText
    10.     SQLSELECT=x
    11. End Function
    Do Good. Be Good. The World is yours.

  5. #5

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: Can you help me solve my problem ? Thanks you

    Quote Originally Posted by vksingh24
    In your code the function SQLSELECT return the recordset.

    You need to declare one local recordset and then open it and return it as the function value

    vb Code:
    1. Public Function SQLSELECT(pstrFIELD As String, pstrTABLE As String, pstrWHERE As String, pstrGROUPBY As String, pstrOrderBy As String, pstrDBName As String) As ADODB.Recordset
    2.  
    3.     Dim pstrSELECT As String
    4.     pstrSELECT = " SELECT " & pstrFIELD & " FROM " & pstrTABLE & pstrWHERE & _
    5.     pstrGROUPBY & pstrOrderBy
    6.     Call SQLExecute(pstrDBName)
    7.      Dim x as ADODB.RECORDSET
    8.      SET x=new ADODB.RECORDSET
    9.      x.Open pstrSELECT, conn, adOpenKeyset, adLockPessimistic, adCmdText
    10.     SQLSELECT=x
    11. End Function
    Thank Sir

    I had tried your method, but i used
    VB Code:
    1. Set SQLSELECT = X
    else it prompt me an error message.

    How ever my rslogin always return NOTHING
    and Prompt me an error message Type mismatch.

    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  6. #6

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: Can you help me solve my problem ? Thanks you

    Oppss !! I solved the problem
    i must declare
    vb Code:
    1. Dim rSLogin As adodb.Recordset
    Instead of
    vb Code:
    1. Dim rSLogin As Recordset

    Thanks sir , you help me a lot.
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width