Hi folks
I have developed a project in access as a backend and excel as a frontend so all the coding is in excel/vba.
I am writing the following function but becvause I have to refer a table in access database , I need to open the recordset and use that table name in the dmax statement. Please see the code below:
Public Function Func3(AnyPerson As String, AnyStartTime As Date, AnyEndTime As Date) As String
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Documents and Settings\Amanpreet Kaur\Desktop\Sunlife Direct Pilot System.mdb;"
Set rs = CreateObject("ADODB.Recordset")
rs.Open "tblbatchdetails", cn, adOpenKeyset, adLockOptimistic, adCmdTable
Dim dtmLower As Date
Dim dtmUpper As Date
dtmUpper = AnyStartTime
dtmLower = nz(DMax("Finishtime", "tblbatchdetails", "[Name]='" & AnyPerson & "' and [Date1]=dateserial(" & Format(Date, "yyyy,mm,dd") & ")"))
Dim dtmtotaltime As Date
dtmtotaltime = dtmUpper - dtmLower
If dtmtotaltime = dtmUpper Then
Func3 = "00:00:00"
Else
Func3 = dtmtotaltime
End If
End Function
I have a problem in code in red colour as tblbatchdetails is a table in access so how can we connect the frontend to this table. If I keed the access database opened while running the userform then it works fine but if the access database is closed and we try to tun the userform then it gives reserved error 2950 in dmax statement.
Thanks for any help.
Aman
Bookmarks