VB SQL Problem

Go4Expert Member
22Jun2006,13:32   #1
Xodiox's Avatar
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
Go4Expert Member
22Jun2006,14:49   #2
rahulnaskar's Avatar
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
Go4Expert Member
22Jun2006,15:01   #3
Xodiox's Avatar
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.
Go4Expert Member
22Jun2006,15:17   #4
Xodiox's Avatar
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
Go4Expert Member
23Jun2006,12:30   #5
Xodiox's Avatar
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.
Go4Expert Member
23Jun2006,13:23   #6
rahulnaskar's Avatar
Good job done, best of luck...

Rahul