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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Tables from USER PROMPT 1

Status
Not open for further replies.

ROhri

IS-IT--Management
Nov 24, 2000
3
US
I'm new to Access and VBA.. I have designed an access database for a project and need help with code for a module to prompt the user for a Studnet number and open a table named Student to access the attribute: Student_ID and compare it to the prompt to see if the student is a valid student. I would appreciate any assistance on this. Thanks!
 
here is a command button I used to make it.
-----------------
Private Sub Command0_Click()
'On Error GoTo Err_Command0_Click

Dim retval As Variant
retval = InputBox("Enter student ID", "Student ID", "")

Dim db As Database, rst As Recordset, SQL As String
Set db = CurrentDb
' SQL string.
SQL = "SELECT * FROM Students WHERE StudentID = '" & retval & "';"
Set rst = db.OpenRecordset(SQL)
If rst.RecordCount > 0 Then
MsgBox "Found Student " & rst!StudentID & " - " & rst!Name, vbInformation, "Found Student"
Else
MsgBox "Student ID " & retval & " Not found!!!", vbExclamation, "Missing student ID"
End If

rst.Close
db.Close

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub
----------------------

DougP, MCP
dposton@universal1.com

Ask me how Bar-codes can help you be more productive.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top