Problem with Select

G

Guest

Hi, I have a table (Departments) and 2 fields DeptCode (Key) and DeptName, I
have these fields in a Form and I also have a text box Text95, what I want to
do is to type the department code in the text95 and display the description,
later on I will display more information but for now I want to try just with
the description, I created a command button with the code bellow but when I
typed the code like "IT" and click the command buttom, open a message box
asking to include that information (IT), I am new in VBA but I have used
select instructions before and this never happened to me before, if someone
can help me I would appreciate it.

Thanks

Private Sub Command6_Click()
Dim Sql As String

Sql = "SELECT Departments.DeptCode, Departments.DeptName " & _
"FROM Departments WHERE DeptCode = " & [Forms]![AddDepartments]![Text95]

Forms!AddDepartments.RecordSource = Sql

End Sub
 
A

Arvin Meyer [MVP]

The contents of Text95 is text, not numeric:

DeptCode = """ & [Forms]![AddDepartments]![Text95] & """"

That's 3 double-quotes and 4 double-quotes
 
G

Guest

Thanks Buddy it works like magic.

Arvin Meyer said:
The contents of Text95 is text, not numeric:

DeptCode = """ & [Forms]![AddDepartments]![Text95] & """"

That's 3 double-quotes and 4 double-quotes
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Orlando said:
Hi, I have a table (Departments) and 2 fields DeptCode (Key) and DeptName,
I
have these fields in a Form and I also have a text box Text95, what I want
to
do is to type the department code in the text95 and display the
description,
later on I will display more information but for now I want to try just
with
the description, I created a command button with the code bellow but when
I
typed the code like "IT" and click the command buttom, open a message box
asking to include that information (IT), I am new in VBA but I have used
select instructions before and this never happened to me before, if
someone
can help me I would appreciate it.

Thanks

Private Sub Command6_Click()
Dim Sql As String

Sql = "SELECT Departments.DeptCode, Departments.DeptName " & _
"FROM Departments WHERE DeptCode = " & [Forms]![AddDepartments]![Text95]

Forms!AddDepartments.RecordSource = Sql

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top