Results 1 to 3 of 3

Thread: find the prob

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    find the prob

    this code gives error that no value given to 1 or more required parameters
    and shows ps = nothing
    in line set ps =objconn.execute(p)

    i am using a combo box to show a list of products and when a product is selected its related article num is shown in the text box



    Private Sub Command1_Click()
    Dim objConn As ADODB.Connection
    Set objConn = New ADODB.Connection
    objConn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data source=c:\database\DB.mdb;Persist Security Info=False")
    Dim p As String
    p = " select article from product where pname =" & Combo1.Text & " "
    Set ps = objConn.Execute(p)
    Text1.Text = p
    Form11.Text1.Text = Combo1.Text
    Form11.Show
    End Sub

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

    Re: find the prob

    You have several things going amiss here.

    When running a SELECT query, you need to use the Open method of the recordset object. You do not use the connection object.

    Also, for your own benefit, use variables that mean something.
    VB Code:
    1. 'by looking at the code I can figure out what is going on
    2. 'but, this is not a good coding practice to get into
    3. Dim p As String
    Try this
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim objConn As ADODB.Connection
    3. Set objConn = New ADODB.Connection
    4. Dim objRS As ADODB.Recordset
    5. Set objRS = New ADODB.Recordset
    6. objConn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data source=c:\database\DB.mdb;Persist Security Info=False")
    7. Dim sSQL As String
    8. sSQL = "select article from product where pname = '" & Combo1.Text & "' "
    9. 'NOTE:  Strings must be encapsulated in single quotes
    10. objRS.Open sSQL, objConn
    11. Text1.Text = objRS.Fields.Item("article").Value
    12. objRS.Close
    13. Set objRS = Nothing
    14. End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    Re: find the prob

    Quote Originally Posted by Hack
    You have several things going amiss here.

    When running a SELECT query, you need to use the Open method of the recordset object. You do not use the connection object.

    Also, for your own benefit, use variables that mean something.
    VB Code:
    1. 'by looking at the code I can figure out what is going on
    2. 'but, this is not a good coding practice to get into
    3. Dim p As String
    Try this
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim objConn As ADODB.Connection
    3. Set objConn = New ADODB.Connection
    4. Dim objRS As ADODB.Recordset
    5. Set objRS = New ADODB.Recordset
    6. objConn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data source=c:\database\DB.mdb;Persist Security Info=False")
    7. Dim sSQL As String
    8. sSQL = "select article from product where pname = '" & Combo1.Text & "' "
    9. 'NOTE:  Strings must be encapsulated in single quotes
    10. objRS.Open sSQL, objConn
    11. Text1.Text = objRS.Fields.Item("article").Value
    12. objRS.Close
    13. Set objRS = Nothing
    14. End Sub

    thanx it really worked

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