Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   VB SQL Problem (http://www.go4expert.com/forums/vb-sql-problem-t919/)

Xodiox 22Jun2006 13:32

VB SQL Problem
 
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 22Jun2006 14:49

Re: VB SQL Problem
 
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 22Jun2006 15:01

Re: VB SQL Problem
 
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 22Jun2006 15:17

Re: VB SQL Problem
 
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 23Jun2006 12:30

Re: VB SQL Problem
 
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 23Jun2006 13:23

Re: VB SQL Problem
 
Good job done, best of luck...

Rahul


All times are GMT +5.5. The time now is 17:24.