Compile Error Object Required Vba Access
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more run time error 424 object required vba about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users runtime error 91 Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping invalid qualifier vba each other. Join them; it only takes a minute: Sign up Trying to trouble Object required error in VBA up vote 0 down vote favorite I got this problem. I have a form that retrieves a table data
Set Vba
using the forms' record source property. When the form's opened, I set its record source property to a module's public method RetrieveMembers. Here's the code below. Private Sub Form_Open(Cancel As Integer) 'set Form's record source property to retrieve a Members table Me.RecordSource = mod_JoinMember.RetrieveMembers End Sub 'mod_JoinMember Class Public Function RetrieveMembers() As String Dim strSQL As String Set strSQL = "SELECT tbl_Member.Title, tbl_Member.Gender, tbl_Member.LastName, tbl_Member.DateofBirth, tbl_Member.Occupation, tbl_Member.PhoneNoWork, tbl_Member.PhoneNoHome, tbl_Member.MobileNo, tbl_Member.Email, tbl_Member.Address, tbl_Member.State, tbl_Member.Postcode FROM tbl_Member;" RetrieveMembers = type mismatch vba strSQL End Function Object required error is thrown. I couldn't comprehend this compile error. I see no wrong with my code since recordsource is a String type property. And my module's function Retrievemembers is returning a String value. Why is it that it's not satisfied with this? sql compiler-errors access-vba share|improve this question asked Jan 30 '12 at 4:43 awongCM 44541330 what line is the error thrown on? (I suspect in code not shown...) –Mitch Wheat Jan 30 '12 at 4:49 It's thrown at the Public Function RetrieveMembers as String line. Just a little info - while the database application is a MS Access 2003, I'm running MS Access 2007 software on my laptop. FYI –awongCM Jan 30 '12 at 12:23 add a comment| 2 Answers 2 active oldest votes up vote 2 down vote accepted Thanks for your help. I fixed it. The reason was because String is not really an Object to begin with. So the 'Set' keyword is not needed - since you don't need to explicitly declare String-type objects anyway! All good now! share|improve this answer edited Jan 30 '12 at 22:12 answered Jan 30 '12 at 13:15 awongCM 44541330 +1 Well spotted, I completely missed that : ) Worth mentioning that you could shorten your code by removing strSQL and just setting RetrieveMembers to the SQL immed
Links Social Groups Pictures & Albums Members List Calendar Search Forums Show Threads Show Posts Tag Search Advanced Search Find All Thanked Posts Go to Page... Thread Tools Rate Thread Display Modes 01-16-2004, 10:18 AM #1 error 1004 vba swes912 Junior Member Join Date: Jan 2004 Location: denver Posts: 5 Thanks: 0 Thanked
Object Variable Or With Block Variable Not Set
0 Times in 0 Posts compile error: object required- - - -Help! On a form I am trying to update a table with
Object Doesn't Support This Property Or Method Vba
Month and Year that user chooses. I did a test and know that the date from the form is coming through good. The error I get is a compile error object required on the Set stSQL = "......." http://stackoverflow.com/questions/9059437/trying-to-trouble-object-required-error-in-vba Private Sub cmdStartForm_Click() If (Me![lstMonth].Value = Null) Then MsgBox "Please highlight a Month.", vbOKOnly End If If (Me![lstYear].Value = Null) Then MsgBox "Please highlight a Year.", vbOKOnly End If Dim con As Object Dim rs As Object Dim stSQL As String Dim intOption As Integer Set con = Application.CurrentProject.Connection Set rs = CreateObject("adodb.recordset") Set stSQL = "UPDATE [Basin_Supplemental_Demand]SET [month] = " & Me![lstMonth].Value & ", [year] = " & Me![lstYear].Value & "WHERE bsdID=1;" rs.Open stSQL, con, http://www.access-programmers.co.uk/forums/showthread.php?t=60381 1 '1 = adOpenKeyset Thanks for the help!!!! swes912 View Public Profile Find More Posts by swes912 01-16-2004, 10:31 AM #2 dcx693 Registered User Join Date: Apr 2003 Location: Brooklyn Posts: 3,265 Thanks: 0 Thanked 2 Times in 2 Posts You just have an issue with spaces in your statement before the SET keyword and before the WHERE keyword. Try this: Set stSQL = "UPDATE [Basin_Supplemental_Demand] SET [month] = " & Me![lstMonth].Value & ", [year] = " & Me![lstYear].Value & " WHERE bsdID=1;" The .Value property is the default property for controls. You can shorten the command to this: Set stSQL = "UPDATE [Basin_Supplemental_Demand] SET [month] = " & Me![lstMonth] & ", [year] = " & Me![lstYear] & " WHERE bsdID=1;" dcx693 View Public Profile Find More Posts by dcx693 01-16-2004, 05:15 PM #3 Pat Hartman Super Moderator Join Date: Feb 2002 Location: Stratford,Ct USA Posts: 25,623 Thanks: 12 Thanked 1,042 Times in 990 Posts Me![lstMonth].Value = Null is NOT a valid way to check for nulls. This statement will ALWAYS be false regardless of the value of lstMonth. IsNull(Me.[lstMonth]) Is correct. Read help or search here for further explaination on null. Month and Year are both function names and as such should NEVER be used to name user objects and will occassionall
VBA Code & Other Help Excel Help Solved: Compiler error: Object required. If this is your first visit, be http://www.vbaexpress.com/forum/showthread.php?34091-Solved-Compiler-error-Object-required sure to check out the FAQ by clicking the link http://www.pcreview.co.uk/threads/compile-error-object-required.3832807/ above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 3 of 3 object required Thread: Solved: Compiler error: Object required. Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 09-18-2010,06:46 AM #1 Birch81 View Profile View Forum Posts View Blog Entries View Articles VBAX Regular Joined Apr 2010 Posts 46 Location Solved: object required vba Compiler error: Object required. Hello. Iīm having a bit problems solving my problem. I canīt seem to figure out where the problem is? I get an compiler error saying Object required. I have the following code. Global CellNyStdInvEgen As Double Global CellNyStdInvFaelles As Double Global CellNyTaetLavFaelles As Double Global CellNyTaetLavEgen As Double Global CellNyLejlFaelles As Double Global CellNyUngdomFaelles As Double Global CellNyEnfasede As Double Global CellNyLevOver25A As Double Global CellNyPrKW As Double Global CellNyFremtid As Double Global CellNyTotal As Double Global TestType As String Sub AssignCells() ' Ny Installation If ActiveWorkbook.Worksheets(1).Range("F12").Value <> "" Then CellNyStdInvEgen = ActiveWorkbook.Worksheets(1).Range("F12").Value ElseIf ActiveWorkbook.Worksheets(1).Range("F13").Value <> "" Then CellNyStdInvFaelles = ActiveWorkbook.Worksheets(1).Range("F13").Value ElseIf ActiveWorkbook.Worksheets(1).Range("F14").Value <> "" Then CellNyTaetLavFaelles = ActiveWorkbook.Worksheets(1).Range("F14").Value ElseIf ActiveWorkbook.Worksheets(1).Range("F15").Value <> "" Then CellNyTaetLavEgen = ActiveWorkbook.Worksheets(1).Range("F15").Value ElseIf ActiveWorkbook.Worksheets(1).Range("F16").Value <> "" Then CellNyLejlFaelles = ActiveWorkbook.Worksheets(1).Range("F16").Value ElseIf ActiveWorkbook.Worksheets(1).Range("F17").Value <> "" Then CellNyUngdomFaelles = ActiveWorkbook.Worksheets(1).Range("F17").Value ElseIf ActiveWorkbook.Worksheets(1).Range("F18").Value <> "" Then CellNyEnfasede = ActiveWorkbook.Workshee
to write a macro for Outlook 2007, and getting nonsensical compile errors. For example: The following script results in "Compile error: Object required" Sub TestScript() Dim x As Integer Set x = 2 End Sub Am I doing something wrong or is my Outlook VBA just broken? brookh, Jun 13, 2009 #1 Advertisements brookh Guest RE: Compile error: Object required [ANSWER] The "object required" error refers to the "Set" statement, which is only used for assigning objects. When assigning simple variables, do not use "Set". The correct code is: Sub TestScript() Dim x As Integer ' Set x = 2 results in "Compiler error: Object required" x = 2 End Sub "brookh" wrote: > I'm trying to write a macro for Outlook 2007, and getting nonsensical compile > errors. For example: The following script results in "Compile error: Object > required" > > Sub TestScript() > Dim x As Integer > Set x = 2 > End Sub > > Am I doing something wrong or is my Outlook VBA just broken? brookh, Jun 13, 2009 #2 Advertisements Michael Bauer [MVP - Outlook] Guest The Set statement is used only for object variables; but you have declared x as Integer, so x=2 would do it. -- Best regards Michael Bauer - MVP Outlook : Outlook Categories? Category Manager Is Your Tool : VBOffice Reporter for Data Analysis & Reporting :