Solved

Object Required Error

Posted on 2013-06-01
8
355 Views
Last Modified: 2013-06-01
Hi,

I have attached an excel 'Forecast-Tool' and it has the form named 'LoginFrm' created. When I open this excel the 'LoginFrm' would popup to ask for login credentials. I will give user name as 'Prashanth' and the password is 'X'. Once, I click on Login button then I get the error as 'Object Required' This workbook will be connected to 'ForecastToolDatabase.mdb' file which is also attached.

I am not able to identify where is the problem. It would be of great help if you could do the needful. Thanks for your time and support.

Regards,
Prashanth
Forecast-Tool.xlsm
ForecastToolDatabase.mdb
0
Comment
Question by:pg1533
  • 5
  • 3
8 Comments
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39212622
Hi Prashanth,

I changed the modLoginForm code module to read:

Option Explicit                                                             ' *** Added

Public clsADODB                                         As New clsADODB     ' *** Added
Sub btn_Login_Click()
On Error GoTo ErrorHandler
    Dim strUsername As String, strPassword As String
    Dim strQuery As String
    Dim objRSet                                         As Recordset        ' *** Added
    
    If Trim(LoginFrm.LoginFrmUserText.Text) = "" Or Trim(LoginFrm.LoginFrmPassTxt.Text) = "" Then
        MsgBox "Please fill all login credentials", vbExclamation, "Login Fail"
    Else
        'WSLogin.lblError.Caption = ""
        Call clsADODB.ConnecttoDatabase
        Set objRSet = New Recordset                                         ' *** Added
        objRSet.CursorType = adOpenStatic
        objRSet.Open "SELECT UserDetails.UserName, UserDetails.FullName, UserDetails.UserCat, UserDetails.Password FROM UserDetails WHERE (((UserDetails.UserName)='" & Trim(LoginFrm.LoginFrmUserText.Text) & "') AND ((tblUser.Password)='" & Trim(LoginFrm.LoginFrmPassTxt) & "'));", clsADODB.objCon
        If objRSet.RecordCount <> 0 Then
            If Trim(LoginFrm.LoginFrmUserText.Text) = objRSet.Fields("UserName") _
            And Trim(LoginFrm.LoginFrmPassTxt) = objRSet.Fields("Password") Then
                
                MsgBox "Success", vbInformation
                
            Else
            
                MsgBox "Fail", vbCritical
            
            End If
        
        Else
                
            MsgBox "Fail", vbCritical
            
        End If

    End If
    
If clsADODB.objCon.State = adStateOpen Then clsADODB.objCon.Close
Exit Sub
    
ErrorHandler:
        MsgBox Err.Description, vbInformation, "Error Information"
End Sub

Open in new window



I also changed the clsADODB.ConnecttoDatabase() subroutine.

The previous line:
strConn = "ODBC;DBQ=" & ActiveWorkbook.Path & "\ForecastToolDatabase.mdb;Driver={Microsoft Access Driver (*.mdb)}"

Open in new window


Now reads:
strConn = "ODBC;DBQ=" & ThisWorkbook.Path & "\ForecastToolDatabase.mdb;Driver={Microsoft Access Driver (*.mdb)}"

Open in new window


(ActiveWorkbook becomes ThisWorkbook)

The code now progresses to the SQL statement within the modLoginForm.btn_Login_Click() subroutine:

objRSet.Open "SELECT UserDetails.UserName, UserDetails.FullName, UserDetails.UserCat, UserDetails.Password FROM UserDetails WHERE (((UserDetails.UserName)='" & Trim(LoginFrm.LoginFrmUserText.Text) & "') AND ((tblUser.Password)='" & Trim(LoginFrm.LoginFrmPassTxt) & "'));", clsADODB.objCon

Open in new window


However, this fails with the error message:
"[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2."

Do you need this problem resolving or are you capable of looking at this yourself?

BFN,

fp.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39212633
PS. The reason for the change that was necessary within the clsADODB.ConnecttoDatabase() subroutine was due to the incomplete advice you were offered here:

[ http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28144627.html#a39212381 ]
0
 

Author Comment

by:pg1533
ID: 39212684
It would be of great help and I really appreciate, if you could resolve this problem also. Thank you so much for your time, patience and support.

Regards,
Prashanth
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39212739
Hi again,

Change this line:
objRSet.Open "SELECT UserDetails.UserName, UserDetails.FullName, UserDetails.UserCat, UserDetails.Password FROM UserDetails WHERE (((UserDetails.UserName)='" & Trim(LoginFrm.LoginFrmUserText.Text) & "') AND ((tblUser.Password)='" & Trim(LoginFrm.LoginFrmPassTxt) & "'));", clsADODB.objCon

Open in new window


To read like this:
objRSet.Open "SELECT UserName, FullName, User_Cat, Password FROM UserDetails WHERE UserName='" & Trim(LoginFrm.LoginFrmUserText.Text) & "' AND Password='" & Trim(LoginFrm.LoginFrmPassTxt) & "'", clsADODB.objCon

Open in new window


You should then see the "Success" (information) MessageBox.

BFN,

fp.
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 500 total points
ID: 39212744
PS. I would also consider removing the first line from the ConnecttoDatabase() subroutine within the clsADODB class module:

Application.ScreenUpdating = False

Open in new window


Good luck with the rest of your project.
0
 

Author Comment

by:pg1533
ID: 39212912
Hi Fanpages,

You are Genius. Thank you so much for all your support and time. I would continue to work on the project. I would definitely raise another question if I get any doubt.

Once again thank you so much. Take care.

Regards,
Prashanth
0
 

Author Closing Comment

by:pg1533
ID: 39212914
Thank you
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39212932
You are very welcome, Prashanth.

If I spot your further question(s), & nobody else is assisting you, I will try to contribute if I am able to.

BFN,

fp.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now