Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2004
    Posts
    20

    Unanswered: how do i program a cmd button to copy data from a txtbox 2a txtbox in another frm

    I need to set a command button to copy the data in a txt box (Patient ID) to a txt box in another form (Patient ID)..the command button has to also open the form that it just copied the data into......please help me...please

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    depending where the code is:


    me.theLocalTextBox = forms!theDistantForm.theDistantTextBox

    or

    forms!theDistantForm.theDistantTextBox = me.theLocalTextBox




    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Mar 2004
    Posts
    20
    i just tried that and an error message popped up sayin...
    Run-time error '2450':
    Microsoft Access cant find the form 'Admissions' reffered to in a macro expression or visual basic code.



    Private Sub cmd01_Click()
    Me.txtPatientID = Forms!Admissions.txtPatientID2
    End Sub

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    First, you will need to Open your Form and to make sure it is, you need the IsLoaded function:

    Code:
    Private Sub cmd01_Click()
       DoCmd.OpenForm "Admissions", , , , acFormAdd
       DoEvents
       If IsLoaded("Admissions") then
          Forms![Admissions].txtPatientID2 = Me.PatientID
       End If
    End Sub
    or somethin like that...

  5. #5
    Join Date
    Nov 2003
    Posts
    1,487
    Now that I have seen your previous post...here is the IsLoaded function:

    Code:
    Function IsLoaded(ByVal strFormName As String) As Boolean
     ' Returns True if the specified form is open in Form view or Datasheet view.
        
        Const conObjStateClosed = 0
        Const conDesignView = 0
        
        If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
            If Forms(strFormName).CurrentView <> conDesignView Then
                IsLoaded = True
            End If
        End If
    End Function

  6. #6
    Join Date
    Mar 2004
    Posts
    20
    now i got an error saying....
    Compile Error:
    Sub or Function not defined

    and the "IsLoaded" bit is highlighted

  7. #7
    Join Date
    Nov 2003
    Posts
    1,487
    Use the provided IsLoaded function above....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •