Results 1 to 7 of 7
  1. #1
    humtake is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2016
    Posts
    26

    "Update" button opens new form with one field box, then updates text box in first form

    Still building my new database and have an update/focus issue. I really appreciate the help you guys provide; let me know if I can explain any of the below better.

    1. I want to be able to click on a button that says "Add Update". It opens a new form that only has one text box and a button. I want to enter in information to that text box and then click the button, which will then close the second form and add the text I just entered in to a field in the first form. The code I have is below:

    [code]
    Private Sub cmd_Submit_Click()
    Dim NewUpdate As String
    NewUpdate = txt_PaymentNewUpdate.Text
    DoCmd.Close
    Forms!frm_Add_Update_Payment_Exceptions!txt_Paymen tUpdates.SetFocus
    txt_PaymentUpdates.Text = txt_PaymentUpdates.Text & NewUpdate
    End Sub
    [\code]



    Logically, I would think this would work. It sets a variable, assigns whatever I type into the text box as that variable, closes the form, sets focus on the field I want to update in the first form, then adds the update to the already existing text in that field.

    Every time I run this, I get "RT error 2185: You can't reference a property or method for a control unless the control has the focus" and the second form never closes. So it looks like I'm having focus issues. Any chance I'm doing something wrong or am I trying to do something using the wrong code?


    2. There is another option I can use which works almost perfectly and I'd prefer this method anyways:
    To do the same thing as above, I have a button that opens an InputBox, sets what I type as a variable, sets the focus on the text box, and appends the data. However, I have 2 issues I can't seem to resolve and not sure if it's even possible.
    a. The InputBox input line is too small. The person who is inputting will need to see all of the text they put in so I need a much bigger input box. I'm not talking about character length which I think is hard set to 1024, I'm referring to the actual physical viewing size of the input box.
    b. When I click Ok, the text I put in the input box appends to the correct TextBox, which works perfectly. Unfortunately, I can't get it to append on a new line so it adds it right after the last character of the existing text. I've tried using every variant of &= I can but just can't get it to work. It always errors out. The code for this is:

    Code:
    Private Sub Command85_Click()
        Dim NewUpdate As String
        NewUpdate = InputBox("Enter new update")
        Me.txt_PaymentUpdates.SetFocus
        Me.txt_PaymentUpdates.Text = Me.txt_PaymentUpdates.Text & NewUpdate
    End Sub

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,730
    humtake,

    Do you have a clear description(plain English) of what your database is intended to support?

    Seems you know what you are doing, but from my perspective I see a lot of how (tables, buttons etc).

    It isn't clear to me what your tables really represent.
    Perhaps you could tell us more; provide an example with data; or post a copy of the database(remove anything confidential first).

    Good luck.

  3. #3
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Create a form and set Popup and Modal both to true. Set the size to be small and it will look and behave like an input box, except under your control. The user will enter something, close the form and in the OnClose event you can update the first form's data. That line of code should be a simple Forms!Mainformname!txt_PaymentUpdates = Forms!Mainformname!txt_PaymentUpdates & Me!NewUpdate

  4. #4
    humtake is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2016
    Posts
    26
    Thanks guys!

    To answer orange, the form is for tracking problem tickets. I have a search box where someone enters in the number of a ticket and it brings up the results. There is a field called "txt_PaymentUpdates" where someone can update the ticket with a new status. I want to make that field read-only and have the user be forced to click an "Add Update" button but I need to keep all old statuses in there. So anything entered into the new popup will append to the txt_PaymentUpdates field.

    aytee11:

    I like the logic of that so I tried it but I'm getting the same error where it says "You can't reference a property or method for a control unless the control has the focus. Even when I put this in the On Close event, when I click the Submit button the form seems to still stay there and doesn't close, just gives that error. I've tried massaging the code but can't find a way to get it to work:

    Code:
    Private Sub cmd_Submit_Click()
        DoCmd.Close
    End Sub
    Private Sub Form_Close()
        Dim NewUpdate As String
        NewUpdate = txt_PaymentNewUpdate.Text
        ' Forms!frm_Add_Update_Payment_Exceptions!txt_PaymentUpdates.SetFocus
        Forms!frm_Add_Update_PPaymentExceptions!txt_Paymentpdates = Forms!frm_Add_Update_PPaymentExceptions!txt_PPaymentpdates & Me!NewUpdate
    End Sub
    I've tried removing the setfocus line, not having a DoCmd.Close event, and other forms but always end up getting an error.

  5. #5
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,476
    This code worked on the 2nd form in a close button. No pop up or model on 2nd form. I added the close button to 2nd form, then converted the macro to vba for that button on that 2nd form. vUpdate is a field on the 2nd form. So I open first form, click button to open 2nd form. Then on 2nd form I add value to vUpdate field, then hit close button which runs code below and on First form the value was added to ID3 on first form.

    Forms![Form1]![ID3] = Forms![Form1]![ID3] & Me.vUpdate
    DoCmd.Close , ""

  6. #6
    humtake is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2016
    Posts
    26
    Thanks Bulzie, that code worked perfect. It looks like the same logic I had, I just overcomplicated it. Greatly appreciated! And thanks as well to the other posters.

  7. #7
    humtake is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2016
    Posts
    26
    Ok, at the risk of wearing out my welcome, there is one other function I'm trying to get this part of the form to do but not sure if there is a shorter way to do it than I imagine.

    This same form also has a field that references a related ticket number (see my post https://www.accessforums.net/showthread.php?t=63112). I'd like the Update button to not only update the first form's "Update" field (which it does thanks to this thread), but I'd also like it to update the "Notes" field of the related ticket by appending the new Update. In short...Two different forms, two different field names, same update is appended to both.

    I can work on doing this by declaring the "Related ticket" as a variable, searching the other ticket table, and adding the update to the "Notes" field once it finds it. But is there an easier way to do this by using the same button I created in this thread? I tried referencing the subform which is just an exact copy of the "Related ticket" form but it says it can't find the subform I'm referencing. The code is below, I gave it a shot at something easy but of course that didn't work:

    Code:
     Private Sub cmd_Submit_Click()
         Forms!frm_Add_Update_Payment_Exceptions!txt_PaymentUpdates = Forms!frm_Add_Update_Payment_Exceptions!txt_PaymentUpdates & vbNewLine & vbNewLine & Me.txt_PaymentNewUpdate_Date
         Forms!frm_Add_Update_Payment_Exceptions!txt_PaymentUpdates = Forms!frm_Add_Update_Payment_Exceptions!txt_PaymentUpdates & vbNewLine & Me.txt_PaymentNewUpdate_Name
         Forms!frm_Add_Update_Payment_Exceptions!txt_PaymentUpdates = Forms!frm_Add_Update_Payment_Exceptions!txt_PaymentUpdates & vbNewLine & Me.txt_PaymentNewUpdate
         
     ' Update related ticket (doesn't work)    
     Forms!frm_Add_Update_Payment_Exceptions!subfrm_Add_Update_SOX_Deficiencies!txt_SOXNotes = Forms!subfrm_Add_Update_SOX_Deficiencies!txt_SOXNotes & vbNewLine & Me.txt_PaymentNewUpdate
         
         DoCmd.Close , ""
     End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Control "what gets the focus" when a form opens?
    By GraeagleBill in forum Forms
    Replies: 3
    Last Post: 12-26-2014, 10:41 PM
  2. Replies: 5
    Last Post: 11-23-2014, 03:54 PM
  3. Replies: 4
    Last Post: 04-08-2014, 09:36 AM
  4. Replies: 8
    Last Post: 10-24-2012, 12:47 PM
  5. Replies: 7
    Last Post: 01-29-2012, 07:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums