VB SQL Problem

Xodiox's Avatar
Go4Expert Member
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
rahulnaskar's Avatar, Join Date: Aug 2004
Go4Expert Member
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
Xodiox's Avatar
Go4Expert Member
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.
Xodiox's Avatar
Go4Expert Member
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
Xodiox's Avatar
Go4Expert Member
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.
rahulnaskar's Avatar, Join Date: Aug 2004
Go4Expert Member
Good job done, best of luck...

Rahul