Asset Upgrade Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Craash
    New Member
    • Jan 2007
    • 18

    Asset Upgrade Form

    Hello, I am fairly new to creating databases with access.
    I am using Access 2003 and have created an Asset tracking database.
    I have a form to enter the asset information with the primary key as the asset ID#, on this form I would like to add a button to open an upgrade form. On the upgrade form I would like to have the Asset ID# field automatically filled in with the one on the form that the button resides. Any ideas? I think that this probably easier than I am making it. Any help would be greatly appreciated.

    Thanks,
    Cr@sh
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by Craash
    Hello, I am fairly new to creating databases with access.
    I am using Access 2003 and have created an Asset tracking database.
    I have a form to enter the asset information with the primary key as the asset ID#, on this form I would like to add a button to open an upgrade form. On the upgrade form I would like to have the Asset ID# field automatically filled in with the one on the form that the button resides. Any ideas? I think that this probably easier than I am making it. Any help would be greatly appreciated.

    Thanks,
    Cr@sh
    Assuming the Form with the button is called frmTracking, and the Text Box containing the ID to carry over is txtAssetID, and the Text Box on the Upgrade Form is also called txtAssetID, then to open the 2nd Form and carry over the Asset ID from the 1st Form:

    Code:
    'In the Click() Event of the button on frmTracking
    Dim stDocName As String
    Dim stLinkCriteria As String
    
    stDocName = "frmUpgrade"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Code:
    'In the Open() Event of the 2nd Form
    Private Sub Form_Open(Cancel As Integer)
      Me![txtAssetID] = Forms![frmTracking]![txtAssetID]
    End Sub

    Comment

    • Craash
      New Member
      • Jan 2007
      • 18

      #3
      Originally posted by ADezii
      Assuming the Form with the button is called frmTracking, and the Text Box containing the ID to carry over is txtAssetID, and the Text Box on the Upgrade Form is also called txtAssetID, then to open the 2nd Form and carry over the Asset ID from the 1st Form:

      Code:
      'In the Click() Event of the button on frmTracking
      Dim stDocName As String
      Dim stLinkCriteria As String
      
      stDocName = "frmUpgrade"
      DoCmd.OpenForm stDocName, , , stLinkCriteria
      Code:
      'In the Open() Event of the 2nd Form
      Private Sub Form_Open(Cancel As Integer)
        Me![txtAssetID] = Forms![frmTracking]![txtAssetID]
      End Sub

      Thanks ADezii,

      Needed the second part...worked great :)

      Comment

      • Craash
        New Member
        • Jan 2007
        • 18

        #4
        My mistake ... this is actually giving a runtime error 2448
        You can't assign a value to this object...The object is a text box the field in the table is a longinteger

        This is producing the error...

        Private Sub Form_Open(Cance l As Integer)
        Me![AssetID] = Forms![frmAssetInfo]![AssetID]
        End Sub

        The field in the table is a long integer...Tried changing it to text and no help...

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by Craash
          My mistake ... this is actually giving a runtime error 2448
          You can't assign a value to this object...The object is a text box the field in the table is a longinteger

          This is producing the error...

          Private Sub Form_Open(Cance l As Integer)
          Me![AssetID] = Forms![frmAssetInfo]![AssetID]
          End Sub

          The field in the table is a long integer...Tried changing it to text and no help...
          It shouldn't make a difference that the Field Data Type is Long Integer, verify your Form and Field names.

          Comment

          • Craash
            New Member
            • Jan 2007
            • 18

            #6
            Stumped

            Originally posted by ADezii
            It shouldn't make a difference that the Field Data Type is Long Integer, verify your Form and Field names.
            The Form and Field names are correct. I have changed the names to obvious wrong names to verify the error would be different and it is, so it is not the naming convention or wrong names within the code.
            Thanks for the help

            Comment

            • Craash
              New Member
              • Jan 2007
              • 18

              #7
              Originally posted by Craash
              The Form and Field names are correct. I have changed the names to obvious wrong names to verify the error would be different and it is, so it is not the naming convention or wrong names within the code.
              Thanks for the help
              The problem seems to be because the AssetID textbox on the upgrade form is bound to the AssetID field in the tblAssetUpgrade . If I make the textbox unbound the code works fine but will not commit the value to the table.

              Comment

              • missinglinq
                Recognized Expert Specialist
                • Nov 2006
                • 3533

                #8
                Try this.
                Code:
                'On the first form button OnClick
                DoCmd.OpenForm "Doctors", acNormal, , , acAdd, , Me.AssetID.Value
                Code:
                'In the code of the second form
                'This allows the form to be opened from the first form OR opened independently 
                Private Sub Form_Load()
                   If Len(Nz(Me.OpenArgs, "")) > 0 And Me.NewRecord Then
                	  Me.AssetID.Value = Me.OpenArgs
                   End If
                End Sub

                Comment

                • Craash
                  New Member
                  • Jan 2007
                  • 18

                  #9
                  Originally posted by missinglinq
                  Try this.
                  Code:
                  'On the first form button OnClick
                  DoCmd.OpenForm "Doctors", acNormal, , , acAdd, , Me.AssetID.Value
                  Code:
                  'In the code of the second form
                  'This allows the form to be opened from the first form OR opened independently 
                  Private Sub Form_Load()
                     If Len(Nz(Me.OpenArgs, "")) > 0 And Me.NewRecord Then
                  	  Me.AssetID.Value = Me.OpenArgs
                     End If
                  End Sub
                  Thanks missinglinq, worked great. I tested it several ways before replying...Than ks to both of you for your help

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32645

                    #10
                    Originally posted by missinglinq
                    'This allows the form to be opened from the first form OR opened independently
                    This is a very important point and good developers always allow for an operator opening a form independantly. Another reason (probably more likely) is that you, the developer, will come back at a later date and try to work out what an object (Form; QueryDef; Report; etc) is for and find that it won't work unless some other dependant form is also running and available.

                    Comment

                    • Craash
                      New Member
                      • Jan 2007
                      • 18

                      #11
                      Originally posted by NeoPa
                      This is a very important point and good developers always allow for an operator opening a form independantly. Another reason (probably more likely) is that you, the developer, will come back at a later date and try to work out what an object (Form; QueryDef; Report; etc) is for and find that it won't work unless some other dependant form is also running and available.

                      Thanks for the tips NeoPa...I can use all the advice I can get. I find this very frustrating and rewarding at the same time. :)

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32645

                        #12
                        Pleased to help - though it was really Linq that brought it up (Seems to bring up lots of good ideas :)).
                        The more you use it, the better you get at it and the less frustrating it gets.

                        Comment

                        Working...