Results 1 to 11 of 11

Thread: [RESOLVED] run time error '3061'

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Location
    Cairo
    Posts
    3

    Resolved [RESOLVED] run time error '3061'

    I Create an access 97 db with a table named students and connect it with a vb6 form using data control
    when i search for the recored between two numbers( the caqlculation of 3 subjects exam) i get a run time error '3061' when execute the code below
    can any one you help me in this case

    Private Sub Command1_Click()

    Dim x As Double
    Dim y As Double

    x = InputBox(" Enter First Number")
    y = InputBox(" Enter SecondNumber")


    Data1.RecordSource = "SELECT * From students WHERE sub1+sub2+sub3 > x And sub1 + sub2 + sub3 < y "
    Data1.Refresh


    End Sub

  2. #2

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: run time error '3061'

    I can only guess as to what message is given for error 3061, but I assume it is complaining about x and y (as they only exist in your VB code, not in the database where the SQL statement is running).

    This can be solved by putting the values of x and y into the SQL statement instead, as shown in the article How can I put the value of a variable/control into my SQL statement? from the "SQL" section of our Database Development FAQs/Tutorials (at the top of the Database Development forum)

  4. #4

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: run time error '3061'

    This needs to be addressed. I'm not precisely sure what you are trying to do here so I going to proceed under the assumption that the "subs" are fields in your database and that each need to contain a value greater than x and less then y to meet your criteria. If this is true then
    Code:
    'you would need to change this
    WHERE sub1+sub2+sub3 > x And sub1 + sub2 + sub3 < y
    'to this
    WHERE sub1 > x
    AND sub2 > x
    AND sub3 > x
    AND sub1 < y
    And sub1 < y
    AND sub3 < y

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: run time error '3061'

    Quote Originally Posted by MartinLiss
    3061 = "Application-defined or object-defined error"
    Unfortunately that message is just VB's way of saying "I don't know".

    Adding the relevant references/components may well be enough to make it show the proper message, but in some cases (particularly when databases are involved) the error message is actually generated at runtime.

    A quick web search on "error 3061" shows many cases of the message being "Too few parameters. Expected n", which is usually caused by the issue I explained - so the link I provided will hopefully solve the error.

  7. #7
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: run time error '3061'

    Same as others, I am not sure what you want to do, perhaps it should be like this:

    Data1.RecordSource = "SELECT * From students WHERE (sub1+sub2+sub3) > " & x & " And (sub1 + sub2 + sub3) < " & y
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

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

    Re: run time error '3061'

    Also if you are going to be adding fields then they should be of the proper data types.

    sub1+sub2+sub3

    Should all be numeric data types.
    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

  9. #9

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Location
    Cairo
    Posts
    3

    Re: run time error '3061'

    Quote Originally Posted by anhn
    Same as others, I am not sure what you want to do, perhaps it should be like this:

    Data1.RecordSource = "SELECT * From students WHERE (sub1+sub2+sub3) > " & x & " And (sub1 + sub2 + sub3) < " & y

    thanks to all
    the code above fix the error, and when i type it as show the error '3061' disappeared.

    thanks again

  10. #10
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: run time error '3061'

    Now that we've helped you, you can help us by pulling down the Thread Tools menu and selecting the Mark Thread Resolved item which will let everyone know that you have your answer. Also if someone has been particularly helpful you have the ability to affect a their forum "reputation" by rating their post. Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see it and know that you appreciate their help.

  11. #11

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Location
    Cairo
    Posts
    3

    Re: run time error '3061'

    Si the Greek, Martin Liss , Hack , Anhn and Robdog888
    thank you for your help
    i do appreciate that

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