I am new to Excel VBA. I have a UserForm in which I am trying to populate records of exception entered by employee for the current month. I have a database called Ofc. Under which I have a table Codeusage.
Primary key is Sno. Here is Name of fields in table Codeusage details the structure and Records saved.
Objective: For example if I want to see all exceptions 43243312 has updated for the month of Oct then it should show three records.
The contents of the Codeusage table:
Sno PeoplesoftId Date of exception Start of exception End of exception Exception time in minutes Code used Reason for code usage Authorized By 36 43243312 10/7/2015 12:10:00 AM 12:15:00 AM 05 Code 11 - Coaching fg Maddala 37 43243312 10/7/2015 4:20:40 AM 4:35:40 AM 15 Code 3 - Team Meeting lsdfj Abhishek 38 43243309 10/7/2015 1:00:00 AM 1:15:00 AM 15 code 19 - onetoone kwjke Atanu 39 43243312 10/6/2015 12:00:00 AM 12:10:00 AM 10 Code 11 - Coaching sajjkh Maddala
Design view of table
Sno AutoNumber PeoplesoftId Text Date of exception Date/Time Start of exception Date/Time End of exception Date/Time Exception time in minutes Text Code used Text Reason for code usage Text Authorized By Text
This is the sql statement written:
SQL1 = "SELECT * FROM CodeUsage where PeoplesoftId=" & "'" & var & "'" & " or format(Date of exception,""MM"")=" & "'" & Format(Now, "MM") & "'" & ""
But is giving an error.
A couple of points:
You'll have to adjust the code below to meet the specific requirements of your database (you don't mention which one), but this is what I would do for something like SQL Server or SQLite. Note, I've referenced
Microsoft ActiveX Data Objects 6.1 Library
via Tools -> References):