Results 1 to 8 of 8

Thread: VBA excel password problem

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    10

    VBA excel password problem

    I created a typical password program with VB using adodc's that
    asked the user to input a username and password when logging in etc.
    This works fine in VB but i have tryed to run this in VBA for Excel
    and the connection doesnt seem to work. Here is my FormLoad:

    Private Sub Form_Load()

    Set con = New ADODB.Connection
    Dim ssql As String
    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=YYYYYYYYY"
    con.Open

    end sub

    Here is the code under my OK command button on the login form:

    ssql = "select * from login where username='" & Text1.Text & "' and password='" & Text2.Text & "'"
    rs.Open ssql, con, adOpenDynamic, adLockOptimistic


    When i click OK after inputting my username and password I receive an
    error message saying "the connection cannot be used to perform this operation.It is either closed or invalid in this context".
    Everything seems to be in order except for "con"

    Any suggestions or advice otherwise? It would be greatly appreciated

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBA excel password problem

    Did you add a reference to MS ActiveX Data Objects 2.x Object library?
    Can you verify if the DSN is correctly connecting to the db?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    10

    Re: VBA excel password problem

    i have referenced that particular library, im not sure about the DSN though

  4. #4
    New Member
    Join Date
    Jul 2005
    Posts
    15

    Re: VBA excel password problem

    Have you Dim'd and Set rs?

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    10

    Re: VBA excel password problem

    yes i have, still not working! very strange

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VBA excel password problem

    I just noticed that your event in Excel is Form_Load. There is no event like that in Excel. If its a UserForm then it would
    be UserForm_Initialize(). If its when Excel opens then its Workbook_Open()
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    10

    Re: VBA excel password problem

    yes that should be it actually, had a feeling there was something different with vba in excel, thats great, thanks very much!

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    10

    Re: VBA excel password problem

    excellent, works perfect, thanks robdog

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