Hi,
I'am using MS-access 2007 to create record-set. Problem is that I'am using lot of Dlookup's to extract data which is increasing time to extract details on VBA form. I want to use record-set because I've heard from someone that it will reduce cycle time to extract record details drastically.
Actual problem is that "I don't know about how to create & use recordset"
I'am using saved query to extract data using Dlookup's.
Code till now I've used is as per below. I know it's like hell but any help to make desired output will be highly appreciated.
My Old code with lot of Dlookup's
My new code which I've tried after learning from Internet:
Thanks in advance..!!!
I'am using MS-access 2007 to create record-set. Problem is that I'am using lot of Dlookup's to extract data which is increasing time to extract details on VBA form. I want to use record-set because I've heard from someone that it will reduce cycle time to extract record details drastically.
Actual problem is that "I don't know about how to create & use recordset"
I'am using saved query to extract data using Dlookup's.
Code till now I've used is as per below. I know it's like hell but any help to make desired output will be highly appreciated.
My Old code with lot of Dlookup's
Code:
Private Sub Telecaller_Name_Change()
If (DCount("[Follow_up_date]", "Telecalling_database", "DatePart('d',[Follow_up_date]) = DatePart('d',Date()) And Year([Follow_up_date]) = Year(Date()) And Month([Follow_up_date]) = Month(Date()) And DatePart('d',[Calling_end_date_time]) <> DatePart('d',Date()) AND [Paid_Unpaid_Status] <> 'Paid' AND [CALLER_NAME] =""" & Me.Telecaller_Name & """") > 0) Then
Me.Form_S_No = CurrentProject.AccessConnection.Execute("SELECT Instrument_Number FROM telecalling_database WHERE [Caller_Name] = """ & Me.Telecaller_Name.Value & """ AND [Paid_Unpaid_Status] <> 'Paid' AND DatePart('d',[Calling_end_date_time]) <> DatePart('d',Date()) And DatePart('d',[Follow_up_date]) = DatePart('d',Date()) And Month([Follow_up_date]) = Month(Date()) And Year([Follow_up_date]) = Year(Date())")(0)
Else
If (DCount("[Debit_date]", "Telecalling_database", "Date()>[Debit_date]+10 AND [Paid_Unpaid_Status] <> 'Paid' AND [Calling_Code]='DEBIT' AND [CALLER_NAME] =""" & Me.Telecaller_Name & """") > 0) Then
Me.Form_S_No = CurrentProject.AccessConnection.Execute("SELECT Instrument_Number FROM telecalling_database WHERE Date()>[Debit_date]+10 AND [Calling_Code]='DEBIT' AND [Paid_Unpaid_Status] <> 'Paid' AND [CALLER_NAME] =""" & Me.Telecaller_Name & """")(0)
MsgBox "Old Debit Calling Code case showing unpaid after 10 days of debit date", vbInformation
Else
If (DCount("[MFYP_FRYP]", "Telecalling_Database", "[MFYP_FRYP] = 'MFYP' AND [Paid_Unpaid_Status] = 'Unpaid' AND [Calling_end_Date_time] Is NULL AND [Caller_Name] = """ & Me.Telecaller_Name.Value & """ AND BANK_NAME NOT LIKE '%DEBIT'") > 0) Then
Me.Form_S_No = CurrentProject.AccessConnection.Execute("SELECT Instrument_Number FROM Telecalling_database WHERE [Caller_Name] = """ & Me.Telecaller_Name.Value & """ AND [Calling_end_Date_time] is null AND [MFYP_FRYP]='MFYP' AND [Paid_Unpaid_Status] = 'Unpaid' AND [BANK_NAME] NOT LIKE '%DEBIT' ORDER BY [Bounce_date] ASC, [No_of_Premium_Required] DESC, [Modal_Premium] DESC;")(0)
Else
If (DCount("[MFYP_FRYP]", "Telecalling_Database", "[MFYP_FRYP] = 'FRYP' AND [Paid_Unpaid_Status] = 'Unpaid' AND [Calling_end_Date_time] Is NULL AND [Caller_Name] = """ & Me.Telecaller_Name.Value & """ AND BANK_NAME NOT LIKE '%DEBIT'") > 0) Then
Me.Form_S_No = CurrentProject.AccessConnection.Execute("SELECT Instrument_Number FROM Telecalling_database WHERE [Caller_Name] = """ & Me.Telecaller_Name.Value & """ AND [Calling_end_Date_time] is null AND [MFYP_FRYP]='FRYP' AND [Paid_Unpaid_Status] = 'Unpaid' AND [BANK_NAME] NOT LIKE '%DEBIT' ORDER BY [Bounce_date] ASC, [No_of_Premium_Required] DESC, [Modal_Premium] DESC;")(0)
Else
If (DCount("[MFYP_FRYP]", "Telecalling_Database", "[MFYP_FRYP] = 'RYP' AND [Paid_Unpaid_Status] = 'Unpaid' AND [Calling_end_Date_time] Is NULL AND [Caller_Name] = """ & Me.Telecaller_Name.Value & """ AND BANK_NAME NOT LIKE '%DEBIT'") > 0) Then
Me.Form_S_No = CurrentProject.AccessConnection.Execute("SELECT Instrument_Number FROM Telecalling_database WHERE [Caller_Name] = """ & Me.Telecaller_Name.Value & """ AND [Calling_end_Date_time] is null AND [MFYP_FRYP]='RYP' AND [Paid_Unpaid_Status] = 'Unpaid' AND [BANK_NAME] NOT LIKE '%DEBIT' ORDER BY [Bounce_date] DESC, [No_of_Premium_Required] DESC, [Modal_Premium] DESC;")(0)
Else
MsgBox "There are no more cases for you to do Tele-Calling, Kindly contact Anumeet Kaur/Balvinder Rayat for more details", vbInformation
End If
End If
End If
End If
End If
DoCmd.OpenQuery ("Finding_Telecalling_details")
Plan_Name = DLookup("BASEPLANNAME", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Plan_Type = DLookup("Plan_Type", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
If (Me.Plan_Type.Value = "New ULIP") Then
Me.Plan_Type.BackColor = 10092543
Else
Me.Plan_Type.BackColor = 16777215
End If
Policy_Number = DLookup("Policy_No", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
GO_Code = DLookup("GO_CODE_Ingenium", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Modal_Premium = DLookup("Modal_Premium", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Frequency = DLookup("Frequency", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
ACt_Holder_Name = DLookup("Account_Holder_Name", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Account_Number = DLookup("Account_Number", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Bank_Name_Ingenium = DLookup("Bank_Name_Ingenium", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Client_Name = DLookup("Client_name", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Mobile_No = DLookup("Mobile_No", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Home_No = DLookup("Home_No", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Work_No = DLookup("Work_No", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
No_of_Prem_required = DLookup("No_of_Premium_Required", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Issue_date = DLookup("Issue_Date", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Calling_Code = DLookup("Calling_code", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Customer_comments = DLookup("Customer_comments", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Policy_Type = DLookup("Policy_type", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Agent_Name = DLookup("Agent_Name", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Transaction_Sequence_Number = DLookup("Txn_Reference_No", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
If (IsNull(DLookup("Policy_Paid_to_date", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)) = True) Then
Me.Policy_paid_to_date.Value = "No PTD Concept"
Else
Policy_paid_to_date = DLookup("Policy_Paid_to_date", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
End If
MFYP_FRYP = DLookup("MFYP_FRYP", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Servicing_Agent_ID = DLookup("SERVICING_AGENT_ID", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Agent_Work_No = DLookup("Agent_Work_No", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Agent_Mobile_No_1 = DLookup("Agent_Mobile_No_1", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Agent_Mobile_No_2 = DLookup("Agent_Mobile_No_2", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Agent_Home_No = DLookup("Agent_Home_No", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
INSTRUMENT_NUMBER = DLookup("INSTRUMENT_NUMBER", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Instrument_amount = DLookup("INSTRUMENT_AMOUNT", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Bounce_date = DLookup("Bounce_date", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Bank_name = DLookup("BANK_NAME", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
BOUNCE_REASON = DLookup("BOUNCE_REASON", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Service_provider = DLookup("SERVICE_PROVIDER", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Draw_date = DLookup("DRAW_DATE", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
New_Mobile_No = DLookup("New_Mobile_No", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
New_Landline_No = DLookup("New_Landline_No", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
Policy_Status = DLookup("Status", "Finding_Telecalling_details", "Instrument_number=" & Me.Form_S_No)
If (IsNull(DLookup("Instrument_Number", "History_Telecalling", "Instrument_Number=" & Me.Form_S_No)) = False) Then
DoCmd.OpenForm ("History_Query")
End If
Total_calls_for_the_day = DCount("Calling_end_Date_time", "Telecalling_Database", "[Calling_END_date_Time]>=Date() And Caller_Name = Telecaller_Name")
Total_calls_for_the_month = DCount("Calling_end_Date_time", "Telecalling_Database", "Year([Calling_END_date_Time])=Year(Now()) And Month([Calling_END_date_Time])=Month(Now()) And Caller_Name = Telecaller_Name") + (DCount("Follow_up_date", "History_Telecalling", "Year([Follow_up_date])=Year(Now()) And Month([Follow_up_date])=Month(Now()) And Caller_Name = Telecaller_Name"))
Repeat_calls_for_the_day = DCount("Follow_up_date", "History_Telecalling", "DatePart('d',[Follow_up_date]) = DatePart('d',Date()) And Year([Follow_up_date]) = Year(Date()) And Month([Follow_up_date]) = Month(Date()) And Caller_Name = Telecaller_Name")
Repeat_calls_for_the_month = DCount("Follow_up_date", "History_Telecalling", "Year([Follow_up_date])=Year(Now()) And Month([Follow_up_date])=Month(Now()) And DatePart('d',[Follow_up_date]) = DatePart('d',Date()) And Caller_Name = Telecaller_Name")
Pending_Calls_for_the_Month = DCount("Caller_Name", "Telecalling_database", "Calling_code is null And Caller_Name = Telecaller_name")
End Sub
My new code which I've tried after learning from Internet:
Code:
Dim dbstelecalling_database As dao.Database
Dim rstinst_no As dao.Recordset
Set dbstelecalling_database = CurrentDb
Set rstinst_no = dbstelecalling_database.OpenRecordset("Finding_telecalling_details")
rstinst_no.MoveFirst
strplan_name = rstfinding_telecalling_details!BASEPLANNAME
strplan_type = rstfinding_telecalling_details!Plan_Type
strpolicy_number = rstfinding_telecalling_details!policy_no
strGO_code = rstfinding_telecalling_details!GO_CODE_INGENIUM
strModal_Premium = rstfinding_telecalling_details!Modal_Premium
strfrequency = rstfinding_telecalling_details!Frequency
strAct_Holder_Name = rstfinding_telecalling_details!Account_holder_name
strAccount_Number = rstfinding_telecalling_details!Account_Number
strbank_name_ingenium = rstfinding_telecalling_details!Bank_Name_Ingenium
strClient_Name = rstfinding_telecalling_details!Client_Name
strMobile_no = rstfinding_telecalling_details!Mobile_No
strHome_No = rstfinding_telecalling_details!Home_No
strWork_No = rstfinding_telecalling_details!Work_No
strNo_of_Prem_Required = rstfinding_telecalling_details!No_of_Premium_Required
strIssue_date = rstfinding_telecalling_details!Issue_date
strCalling_code = rstfinding_telecalling_details!Calling_Code
strCustomer_comments = rstfinding_telecalling_details!Customer_comments
strPolicy_type = rstfinding_telecalling_details!Policy_Type
strAgent_name = rstfinding_telecalling_details!Agent_Name
strTransaction_Sequence_Number = rstfinding_telecalling_details!Txn_reference_no
strPolicy_paid_to_date = rstfinding_telecalling_details!Policy_paid_to_date
rstinst_no.Close
dbstelecalling_database.Close
Set rstinst_no = Nothing
Set dbstelecalling_database = Nothing
Thanks in advance..!!!