Results 1 to 6 of 6
  1. #1
    Siuxia is offline Novice
    Windows XP Access 2003
    Join Date
    May 2012
    Posts
    6

    recordset open error on SQL query


    Hello all,
    Been using these forums a lot over the last few days to help me with an Application I'm developing, but I have run in to a problem I can't seem to over come.

    My SQL is pretty weak, and I have just about managed to pull the data I have needed using simple queries. I have had to move on to a JOIN query to accomplish something and it's all gone a bit pear shaped.
    I used the SQL builder to create the query and running it through that it works and pulls the data I want but when I put it in to the VB code it keeps chucking errors at me.

    Here is the code below:
    Code:
    Private Sub cboAllocatedTo_AfterUpdate()
    
    
    Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset
    
    
    strSQL = "SELECT tblAuthTypes.CanAllocate FROM tblAuthTypes INNER JOIN tblUsers ON tblAuthTypes.RecID = tblUsers.RecID WHERE (((tblUsers.UserName)=[Forms]![frmLogin].[txtusername]))"
    
    
    rst.Open strSQL, cnn, adOpenDynamic, adLockReadOnly
    
    
    If rst.EOF = True Then
        MsgBox "This is true"
    Else
        MsgBox "This is false"
    End If
    
    
    End Sub
    When I use this it come up with "No give value for one of more required parameters". When debugging it highlights the following line;
    Code:
    rst.Open strSQL, cnn, adOpenDynamic, adLockReadOnly
    I have used similar code through out my application with no ill effects. Can anyone please shed some light on this.
    Thanks in advance.

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I have used similar code through out my application with no ill effects.
    Can you give us an example from your application where you've used similar code that works?

  3. #3
    Siuxia is offline Novice
    Windows XP Access 2003
    Join Date
    May 2012
    Posts
    6
    Here is a piece of working code, the only thing I can see that is different is the JOIN query on the first bit of code I posted.
    Code:
    Private Sub btnConfirm_Click()On Error GoTo send_err_handler
    
    
    Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset
    
    
    strSQL = "SELECT EMail FROM tblUsers WHERE UserName='" & Me.txtIssuer & "'"
    
    
    rst.Open strSQL, cnn, adOpenDynamic, adLockReadOnly
    
    
    strMsgBody = "The Engineering Job " & Chr(34) & Me.txtBriefDesc & Chr(34) & " that was created by you on " & Me.txtDateRaised & " has been marked as completed on " & Me.txtDateComp & "."
    
    
    DoCmd.SendObject acSendNoObject, , , rst!EMail, , , "Job Number: " & Me.txtJobNumber & " marked as completed.", strMsgBody, True
    
    
    send_err_handler:
    'not sent error 2501
    If Err.Number = 2501 Then
        MsgBox "Job not sent due to message window being closed!", vbInformation, "Emailing Error"
    Else
        MsgBox Err.Number & " " & Err.Description, vbCritical, "Emailing Error"
    End If
    End Sub

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    strSQL = "SELECT EMail FROM tblUsers WHERE UserName='" & Me.txtIssuer & "'"
    The code in your first post does not have the parts that appear above in red. Have you tried duplicating that and seeing if it will work?

  5. #5
    Siuxia is offline Novice
    Windows XP Access 2003
    Join Date
    May 2012
    Posts
    6
    Quote Originally Posted by Robeen View Post
    The code in your first post does not have the parts that appear above in red. Have you tried duplicating that and seeing if it will work?
    You sir, are a star! It's now pulling the query, now to see if I can get it to do what I want it to do.
    Thanks again.

  6. #6
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Happy to help!!
    All the best.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Recordset Error
    By gazzieh in forum Programming
    Replies: 3
    Last Post: 02-17-2012, 05:13 PM
  2. Excel sheet open in recordset
    By waqas in forum Programming
    Replies: 3
    Last Post: 09-22-2011, 11:47 AM
  3. open recordset with variable SQL
    By rivereridanus in forum Queries
    Replies: 4
    Last Post: 07-27-2011, 12:58 PM
  4. ADO Recordset.Open (SQL) does nothing
    By workindan in forum Programming
    Replies: 3
    Last Post: 06-23-2010, 02:07 PM
  5. Replies: 0
    Last Post: 03-27-2010, 01:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums