Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2007, 08:24 AM
Authorized User
 
Join Date: Jun 2007
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default subform not loading fast enough

I was given the task of reworking a vba form that was given to me. The original programmer used a combo box and after the user picked an item, a subform was loaded and made visible. The subform was loaded nearly instantly and if the user change the selection in the combo box, the form update almost instantly.

When I reworked the form, for some reason, the form has a delay when loading and updating. I now pull information from the subform right after it is loaded to make some calculations but since the form isn't always completely loaded or updated, i get the error: You entered an expression that has no value.

Any suggestions?

 
Old June 28th, 2007, 09:06 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Without the code, I am not sure why the subform loads slowly. Subforms are always problematic beyond merely displaying and updating data.

I would suggest that rather than taking your calculated values from the subform, you take them directly from the results the subform will be displaying, and bypass the subform.

Did that help?


mmcdonal
 
Old June 28th, 2007, 09:34 AM
Authorized User
 
Join Date: Jun 2007
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yea, I understand where you're coming from. You're saying just pull the data from the tables the subform pulls it from. Hence, getting rid of the middle man. The way I rearranged the form requires more steps (which is probably why it is taking it long to load) If I really have to, I will just store values locally and use them.

Here's the before and after code:
before
Code:
Private Sub CUSIP_Number_AfterUpdate()
On Error GoTo Err_CUSIP_Number_AfterUpdate

Me![Broker ID].Visible = True
Me![Broker Short Name1_Label].Visible = True
Me![cusip death holder].Visible = True '<== SUBFORM
Me.Cusip_death_holder.Requery

If Me.[cusip death holder]![Include Interest Flag] = True Then
    Me.Number_Day.Enabled = True       '<== SUBFORM ACCESS
    Me.Accrued_Interest.Enabled = True
Else
   Me.Number_Day.Enabled = False
   Me.Accrued_Interest.Enabled = False
End If

If Me.Cusip_death_holder![Interest Rate] = 0 Then
   Me.Interest = ""
Else
   Me.Interest = Me.Cusip_death_holder![Interest Rate]
End If
 Exit Sub


Err_CUSIP_Number_AfterUpdate:

    MsgBox Error$
    Exit Sub
End Sub
after
Code:
Private Sub CUSIP_Number_AfterUpdate()
On Error GoTo Err_CUSIP_Number_AfterUpdate

If Me![CUSIP Number] <> ".new" Then          'if deceasedHolder has some CUSIPS already
    Me![cusip death holder].Visible = True  '<==== THIS IS THE SUBFORM TO BE LOADED
    Me![lblCompany].Visible = True
    Me![Company ID].Visible = True
    Me![Company ID].Enabled = False
    Me![CompanyIDDisplay].Visible = True

    Me![Broker Short Name1_Label].Visible = True
    Me![Broker ID].Visible = True
    Me![Broker ID].Enabled = False
    Me![BrokerIDDisplay].Visible = True

    Me![PickCusipLabel].Visible = True
    Me![PickCusip].Visible = True
    Me![PickCusip].Enabled = False

    '<About 30 controls visibility set to true>

    Dim db As Database
    Dim rs As Recordset
    Dim rsInterest As Recordset '<= this is current workaround

    Dim sqlString As String
    Dim sqlInterest As String   '<= *

    sqlString = "SELECT deceasedHolder.[Company ID], Company.[Company Short Name], " & _
        " deceasedHolder.[Broker ID], Broker.[Broker Short Name], deceasedHolder.[Date Received], " & _
        " deceasedHolder.[Quantity], deceasedHolder.[Interest], deceasedHolder.[Number Day], deceasedHolder.[Date Entered], " & _
        " deceasedHolder.[Accrued Interest], deceasedHolder.[Next Put Date], deceasedHolder.[Last Payable Date], " & _
        " deceasedHolder.[Met Holding Period], deceasedHOlder.[All Required Paperwork], deceasedHolder.[Original Death Certificate], " & _
        " deceasedHolder.[Misc Comments], deceasedHolder.[Date Entered], deceasedHolder.[Last Update Date], deceasedHolder.[User Id of Last Update] " & _
        " FROM (deceasedHolder INNER JOIN Company ON deceasedHolder.[Company ID]= Company.[Company ID]) " & _
        " INNER JOIN Broker ON deceasedHolder.[Broker ID] = Broker.[Broker ID] " & _
        " WHERE (((deceasedHolder.[Name]) = '" & Me![Name] & "')" & _
        " AND ((deceasedHolder.[Cusip Number]) = '" & Me![CUSIP Number] & "'));"


    Set db = CurrentDb()
    Set rs = db.OpenRecordset(sqlString)

        If Not rs.EOF Then
            '<Populated form with data from rs (not related to subform)
            '<Set some visibilities to true>
        End If
    rs.Close
    Set rs = Nothing

    sqlInterest = "Select * FROM Cusip WHERE Cusip.[Cusip Number] = '" & Me![PickCusip] & "';"
    Set rsInterest = db.OpenRecordset(sqlInterest) '<Workaround for slow subform

        If Not rsInterest.EOF Then
            Me![Interest] = rsInterest![Interest Rate]
            If rsInterest![Include Interest Flag] = True Then
                Me![Number Day].Enabled = True
                Me![Accrued Interest].Enabled = True
                calculate_acrued_interest
            Else
                Me![Number Day].Enabled = False
                Me![Accrued Interest].Enabled = False
                Me![Number Day] = ""
                Me![Accrued Interest] = ""
            End If
        End If
    rsInterest.Close
    Set rsInterest = Nothing
    db.Close

    Me![PickCusip].RowSource = " SELECT Cusip.[Cusip Number] " & _
        "FROM Cusip " & _
        "WHERE Cusip.[Company ID] = '" & Me![CompanyIDDisplay] & "';"


Else '<Irrelevant for the current problem>
End If
Exit Sub
Err_CUSIP_Number_AfterUpdate:

    MsgBox Err.Description
    Exit Sub
End Sub
 
Old June 28th, 2007, 10:30 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I would load the data here, and then do the controls on the Subform's On Current event.

Then take this data as you are getting it in your code, and set controls on the main form as well. Or, add addtional code to the AfterUpdate event to set values on those controls.

Also, you may want to consider basing the subform on a local table, and then build your data into that table. Then the code looks something like:

Take Parameters
SetWarnings False
Delete all data in table
Append new data using parameters to local table
SetWarnings True

COuld be a matter of running a few queries.

mmcdonal
 
Old June 28th, 2007, 10:42 AM
Authorized User
 
Join Date: Jun 2007
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I ended up doing a quickfix. just retrieving the info from the subform's table (but still displaying the subform). Realistically, I'd like to do it another way, but being on a deadline, the runtime is negligible in this case.

Thanks

 
Old June 29th, 2007, 08:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Side note: You're setting the Me.Interest = "" at one point. If Interest holds an interest rate, you cannot assign a string value to something that is supposed to hold a number. You're better off setting Me.Interest = Null.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old July 2nd, 2007, 08:47 AM
Authorized User
 
Join Date: Jun 2007
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Greg. I didn't even think of that. However, Me.Interest is a text box on the form so when I tested it, nothing happened, but it is good practice anyway to do things like that.

 
Old July 5th, 2007, 07:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Yeah, the name "textbox" is misleading IMHO. It should be called something like a data box.

In the case of a bound form, the textbox could hold data of type text, integer, long, single, double, boolean, date, etc. It's based on the table field type. For an unbound form, I assume the textbox merely holds data of type variant until you do something with it and pass it along to a declared variable.



Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
fast connect with c# zaghmout C# 0 October 8th, 2008 02:37 AM
Are vbscript classes fast? atwork8 Classic ASP Basics 0 May 3rd, 2008 11:13 AM
Fast XPath safin XML 4 September 15th, 2005 12:43 PM
Fast printing rajanikrishna Pro VB 6 8 November 24th, 2004 09:39 AM
Filter Subform B Based on Field in Subform A SerranoG Access VBA 3 June 18th, 2004 12:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.