I have a single view form who's data source is derived from Me.Recordsource (see below). I would like to add a text box (Me.JobDescr) to this form who's data is derived from a dlookup command within VBA. When I ran the updated form I noticed that Me.JobDescr
in all of the records does not match up to the appropriate data but instead is/are a copy of the first record. So the solution (I think) is to add the dlookup inside my recordsource. However, VBA is erroring this out as bad syntax. Can someone look at my
syntax and comment on this approach?
Private Sub Form_Open(Cancel As Integer)
Dim strLastname As String
Dim strFirstname As String
Dim strFullName As String
Dim strMgrID As String
strLastname = DLookup("[Lname]", "tblUser", "[UserID] = " & Forms!frmLogin!cboUser)
strFirstname = DLookup("[Fname]", "tblUser", "[UserID] = " & Forms!frmLogin!cboUser)
strFullName = strLastname & ", " & strFirstname
strMgrID = Forms!frmLogin!cboUser
Select Case Forms!frmMainMenu.FrameEE
Case 1
Me.RecordSource = "SELECT tblEmployee.EmplID, tblEmployee.EmplName, tblEmployee.JobCode," & vbCrLf & _
"DLookup("Descr", "tblJobCostCtrCode", "[Code]=" & Me.jobcode) as JobDescr" &vbCrLf & _ 'this is the added line
"tblEmployee.CostCtr, tblEmployee.DOH, tblEmployee.DOT, tblEmployee.MgrID, tblEmployee.DirID " & vbCrLf & _
"FROM tblEmployee WHERE (((tblEmployee.DOT) is null) and ((tblEmployee.MgrID)=" & strMgrID & ")) ORDER BY tblEmployee.EmplName ;"
...
Me.JobDescr.ControlSource= "JobDescr"