1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

VB SQL Problem

Discussion in 'Visual Basic ( VB )' started by Xodiox, Jun 22, 2006.

  1. Xodiox

    Xodiox New Member

    Joined:
    Jun 19, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    Hi everybody,

    I Have a little problem that I hope someone can see, this section of code gives the following error msg:

    Run-time error '-2147217904 (80040e10)': No Value given to one or more required parameters.

    Private Sub Combo1_Click()

    Res.Open "SELECT * FROM Computer WHERE ComputerName=" & Combo1.Text, Con, adOpenDynamic

    Do Until Res.EOF
    Text1.Text = Text1.Text & "" & Combo1.Text & " is in " & Res("RoomName")
    Res.MoveNext
    Loop

    Res.Close

    End Sub

    Anyone got any ideas where the problem is in the code ?

    Thanks
     
  2. rahulnaskar

    rahulnaskar New Member

    Joined:
    Aug 26, 2004
    Messages:
    25
    Likes Received:
    2
    Trophy Points:
    0
    Private Sub Combo1_Click()

    Res.Open "SELECT * FROM Computer WHERE ComputerName=" & Combo1.Text(I suppose you need to insert single quotes, as computername seems to be a text field), Con, adOpenDynamic

    Do Until Res.EOF
    Text1.Text = Text1.Text & "" & Combo1.Text & " is in " & Res("RoomName")
    Res.MoveNext
    Loop

    Res.Close

    End Sub

    Anyway, debug in VB Editor and find out which line of code is causing the problem, then I think we will be able to work things out better.
    Good Luck,

    Rahul
     
  3. Xodiox

    Xodiox New Member

    Joined:
    Jun 19, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    It is this line of code:

    Res.Open "SELECT * FROM Computer WHERE ComputerName=" & Combo1.Text, Con, adOpenDynamic

    and if I write it as:

    Res.Open "SELECT * FROM Computer", Con, adOpenDynamic

    Then it works fine BUT then it doesn't display the correct "RoomName" for the correct "ComputerName" because there is nothing to join them.

    I think that its to do with the & Combo1.Text part and have tried it with single and double quotes but it still complains and doesn't work.
     
  4. Xodiox

    Xodiox New Member

    Joined:
    Jun 19, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    I have just looked at an old program I made in the same way and it has the same line of code:

    Res.Open "SELECT * FROM Kunder WHERE Kundenr=" & Combo1.Text, Con, adOpenDynamic

    This now makes me wonder if the problem is some where else because this program work fine with this line in to :S
     
  5. Xodiox

    Xodiox New Member

    Joined:
    Jun 19, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    Ok I have found out the problem and is now fixed, Old code snippit:

    Res.Open "SELECT * FROM Computer WHERE ComputerName=" & Combo1.text, Con, adOpenDynamic

    And this snippit is correct but ONLY if the input in Combo1.text is in number format.

    New code snippit:

    Res.Open "SELECT * FROM Computer WHERE ComputerName='" & Combo1.text & "'", Con, adOpenDynamic

    This works if the input is in text format.
     
  6. rahulnaskar

    rahulnaskar New Member

    Joined:
    Aug 26, 2004
    Messages:
    25
    Likes Received:
    2
    Trophy Points:
    0
    Good job done, best of luck...

    Rahul
     

Share This Page