VBA syntax when querying SQL database - TechRepublic
Question
March 7, 2016 at 09:53 AM
rjanz59

VBA syntax when querying SQL database

by rjanz59 . Updated 10 years, 3 months ago

I thought I posted this yesterday but can’t locate it so I’ll try again. I’m trying to insert the first and last time entry date from a SQL table into Word but it fails on the typetext line. I think I need to set a string to the first and last item so I can then use that as the typetext but not sure what the syntax is:
Public Sub TimeDates()
Dim rsFirstDate, rsLastDate As Recordset
Dim strMatterNo, strTimeDate As String

‘Get the matter number from the doc
strMatterNo = GetValue(“[MatterTIME]”)
If Len(strMatterNo) < 1 Then Exit Sub End If 'Insert the date of the first unbilled time entry Selection.GoTo what:=wdGoToBookmark, Name:="FirstTime" Set rsFirstDate = modOPDB.Query("select min(WORK_DATE) from [JCTRAN] where MATTER_NO ='" & strMatterNo & "' and billed_flag <> ‘Y’ and billable_flag = ‘y'”)
Selection.TypeText Format(rsFirstDate, “d MMMM yyyy”) & ” to ”
Set rsLastDate = modOPDB.Query(“select max(WORK_DATE) from [JCTRAN] where MATTER_NO ='” & strMatterNo & “‘ and billed_flag <> ‘Y’ and billable_flag = ‘y'”)
Selection.TypeText Format(rsLastDate, “d MMMM yyyy”)

End Sub

This discussion is locked

All Comments