By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 1,911 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

Very basic code help

P: 46
New to visual basic; trying to teach myself. Here is very basic code I am using to try to fill a text box on my form after updating a box that selects an employee ID.

Expand|Select|Wrap|Line Numbers
  1. Dim strsql As String
  2. strsql = "SELECT Wage FROM Employees WHERE NameID = " & Me.EmpNameID
  3. Me.Wage = strsql
However, when updated, the text just shows up in the box as opposed to looking up the wage. What am I doing wrong?

Thank you!
Dec 17 '07 #1
Share this Question
Share on Google+
3 Replies


missinglinq
Expert 2.5K+
P: 3,532
Assuming that NameID is numeric, which your code indicates, why not simply use DLookup()?

Expand|Select|Wrap|Line Numbers
  1. Me.Wage = DLookup("Wage", "Employees", "[NameID] = " & Me.EmpNameID)
If NameID is Text rather than Numeric

Expand|Select|Wrap|Line Numbers
  1. Me.Wage = DLookup("Wage", "Employees", "[NameID] = '" & Me.EmpNameID & "'")
  2.  
Linq ;0)>
Dec 17 '07 #2

P: 46
Perfect - never heard of that. Thank you very much.
Dec 17 '07 #3

missinglinq
Expert 2.5K+
P: 3,532
DLookup works fine when retrieving a single field value.

Glad we could help!

Linq ;0)>
Dec 17 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.