Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
| Search | Today's Posts | Mark Forums Read
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 February 11th, 2005, 02:42 PM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default Copy number from one textbox to another

Hello,
How can I copy a number from one textbox which is in my access from called "fWeightInput" to another textbox in form "fWeight" when a button is clicked in the "fWeightInput" form. Thanks for any ideas

Marcin

 
Old February 12th, 2005, 10:53 AM
Authorized User
 
Join Date: Oct 2003
Location: Cleveland, OH, USA.
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Marcin,

To make the example a little more meaningful, I'll use the
following names for your textboxes and command button:

txtField1 - Textbox field on fWeightInput
txtField2 - Textbox field on fWeight
cmdCopyValue - Button on fWeight to copy the value from fWeightInput

Here is some code that you can use that would be indicated under the
OnClick event property for the button:


Private Sub cmdCopyValue_Click()
   If IsObjectOpen("fWeightInput", acForm) = True Then
      Me.txtField2 = Forms("fWeightInput")("txtField1")
   End If

End Sub



First of all, the "Me" qualifier refers to the current form or
report that you're in - it saves you from having to code:

Forms("fWeight")("txtField2") = Forms("fWeightInput")("txtField1")

If you needed to run this process from a third form, copying
the value from fWeightInput to fWeight, the code directly above is
what you would need to run in order to accomplish it. Also, you
should run the "IsObjectOpen" check on both forms.

The call to the function "IsObjectOpen()" is used to ensure that
the form that you're trying to retrieve the value from is open. In
the event that (in this case) form fWeight was not open when you
tried to click the button, you would get a runtime error. It may
seem a little redundant if that form should always be open, but
it's good to use in a case when attempting to retrieve a value from
another form like this. Here's the code for IsObjectOpen which you
can Copy|Paste directly as a function in your app:

Public Function IsObjectOpen(ByVal strObjectName As String, Optional lngObjectType As Long = acForm) As Boolean
    If fG_DebugMode = False Then
       On Error GoTo Err_IsObjectOpen
    End If

    If SysCmd(acSysCmdGetObjectState, lngObjectType, strObjectName) = acObjStateOpen Then
       If lngObjectType = acForm Then
          If Forms(strObjectName).CurrentView = 1 Then
             IsObjectOpen = True
          Else
             IsObjectOpen = False
          End If
       Else
          IsObjectOpen = False
       End If
    Else
       IsObjectOpen = False
    End If

End Function


The function defaults to type acForm (for forms), but you can use it
for other object types as well. For example "acReport" is used for
reports.

Hope that helps.

Thanks,

Warren
 
Old February 15th, 2005, 09:07 AM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot that worked great. Just what I neeed





Similar Threads
Thread Thread Starter Forum Replies Last Post
disabling copy-paste for a textbox control gaikwad.ganesh C# 3 October 21st, 2008 03:41 PM
auto incrementaion of number in textbox deepthir ASP.NET 2.0 Basics 1 March 26th, 2008 07:15 AM
Textbox Number Formatting pencilneck Visual Basic 2005 Basics 2 October 25th, 2007 03:46 PM
Validate two textbox one for area code and number debjanib ASP.NET 1.0 and 1.1 Professional 1 June 6th, 2006 01:00 PM
Copy auto number value to another form bamajog Access 11 February 10th, 2006 10:24 AM





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