Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB code to Sql Code

Status
Not open for further replies.

jfarrell

Technical User
Mar 3, 2001
15
US
Can someone help me with this.
I have a form with a find command button(cmdFind).
I'm using ADO, VB and Access.
It works but the VB code must be changed to
Sql as a requirement of the project.
The code in Vb needs to be converted to
Sql is as follows.
Private Sub cmdFind()
Dim strLast As String
Dim adoBookmark As Variant
strLast = InputBox("Enter Studentid for search")
If strLast <> &quot;&quot; Then
adoBookmark = Adodc1.Recordset.Bookmark
Adodc1.Recordset.Find &quot;Studentid = &quot; & strLast
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.Bookmark = adoBookmark
MsgBox &quot;Student not Found&quot;
End If
End If
End Sub
The code I am laboring over to try to make work is:
Private Sub cmdFind_Click()
Dim StudentFind As String
Dim sqlFind As String
StudentFind = InputBox(&quot;Enter StudentID&quot;, &quot;Find Student by Studentid&quot;)
sqlFind = &quot;SELECT * FROM Student &quot; & _
&quot;WHERE Studentkey = &quot; & StudentFind
Adodc1.RecordSource = sqlFind
Adodc1.Refresh
end sub
This is on Access tables.
Can anyone look at this and see why it has a problem.
thanks.
John
 
For a start, try converting &quot;StudentFind&quot; to a variable of type &quot;integer&quot; in the formation of &quot;sqlFind&quot;.

mkuan
 
I tried changing the string to integer but that didn't
fix the problem. Anyother ideas please.
John
 
I would suggest trying to type the sql statement all on one line. Also before the command is execute place a msgbox sqlFind.

Sometimes there are spaces or errors that you can pick up by doing this.

Also what is the definition in the Table design on you access statement set to. Is the student id an integer or is set text?

spideysense
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top