Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8916105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:09:01+00:00 2026-06-15T05:09:01+00:00

have an access database with a form that has multiple textboxes for production data.

  • 0

have an access database with a form that has multiple textboxes for production data. I need to do a calculation with a few of the boxes, they are set up as


txtA * txtB * txtC = txtD

I need to take the values from each of the boxes and perform this calculation behind the scenes. So I need the value from txtA * txtB * txtC and display the answer to that calculation in txtD. I keep running into issues because of the number of textboxes on my form it will always pick up the wrong data?? HeLP!

Private Sub btnCalculate_Click()
    Dim ctrl As Control
    Dim txt As TextBox

    For Each ctrl In Form.Controls
        If TypeOf ctrl Is TextBox Then
            Set txt = ctrl
            If txt.Name = "txtD" Then
                Set txt = ctrl
                ctrl.SetFocus
                ctrl.Text = calculate
            End If
        End If
    Next ctrl
End Sub

Public Function calculate()
    Dim calc1 As Double        
    calc1 = txtA.Value * txtB.Value * txtC.Value / 144
End Function

I keep getting this error:

Run-time error ‘2185’:
You can’t reference a property or mathod for a control unless the control has the focus.

This is in regards to txtA, txtB, txtC.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:09:02+00:00Added an answer on June 15, 2026 at 5:09 am

    Try

    txtD = calculate()   
    

    Or

    Me!txtD = calculate()
    

    If, for some reason, you want to access a control by its name, do it like this

    Dim name As String
    
    name = "txtD"
    Me(name) = calculate()
    

    Your calculation function must assign the result to the function name. A potential problem is that you are ignoring types. Of which type is the result of the function? It will be typed as Variant if you don’t specify a type (and a variant can contain about anything). Better

    Public Function calculate() As Double
        calculate = CDbl(txtA.Value) * CDbl(txtB.Value) * CDbl(txtC.Value) / 144
    End Function
    

    Now, everyone who looks at the function knows what kind of data the textboxes should contain and, more important, what kind of result the function returns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an C# form application that use an access database. This application works
I have a MS Access database with few tables and a form. When more
I have a ms access database that has one table for each photo album
I have inherited an Access 2007 database that has been split so the tables
I have an access database with a parent form which has a subform in
I have a database in access 2010. A have a table that has some
I have an Access database (in Access 2003) with several tables, and data must
I have an Access 2007 database that works asynchronously with a MAS200 database. Due
I have an access 2007 Database that outputs a report in excel format, the
I have two tables in my access database that I want to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.