Mattandy55
New Member
- Joined
- May 27, 2016
- Messages
- 20
Hi there, I have the below code I have used for a long time on a specific report.. For some reason, when running and then doing some F8 trouble shooting, it seems to be skipping the .commandtext and the End With. So its not picking up all the results/fully updating. Any ideas as I am lost?
VBA Code:
'HRMS Data
Sheets("Qry1").Select
Range("A3").Select
With Selection.ListObject.QueryTable
.Connection = "ODBC;DRIVER=SQL Server;SERVER=SUN-SRV-SQL\SAGEHRMS;UID=XXXXX;PWD=XXXXX;APP=Microsoft Office;WSID=SUN-SR-RDS2;DATABASE=SageHRMS_Live"
.CommandText = "SELECT hbene.b_empno, hrpersnl.p_ssn, hrpersnl.p_fname, hrpersnl.p_mi, hrpersnl.p_lname, hbene.b_benecode, hbene.b_401eamt, hbene.b_401epct " _
& "FROM SageHRMS_Live.dbo.hbene hbene, SageHRMS_Live.dbo.hrpersnl hrpersnl " _
& "WHERE hrpersnl.p_empno = hbene.b_empno AND hbene.b_company = hrpersnl.p_company AND hrpersnl.p_active In ('A','L') AND hbene.b_beneid='S' AND hbene.b_effdate<={ts '2023-11-22 00:00:00'} AND (hbene.b_expdate Is Null or hbene.b_expdate>{ts '" & Sheets("Lists").Range("C1").Value & " 00:00:00'}) AND (hbene.b_401eamt<>0 or hbene.b_401epct<>0)"
.Refresh BackgroundQuery:=False
End With