Results 1 to 12 of 12
  1. #1
    dhicks is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jun 2017
    Posts
    36

    Run-time error 2489

    Hello,

    I have a main form with a subform. The subform is bound to a table. I am trying to create a command button that will go to a new record in the subform and also auto-populate a field with the current date. This is the code:

    Private Sub cmdNewChkOut_Click()


    Me.Controls("frmChckOutHist").SetFocus
    DoCmd.GoToRecord acDataTable, "tblChkInOutHist", acNewRec
    Me!Reservation_Date = Date


    End Sub

    When I click on the button I get the run-time error 2489 stating that the bound table is not open. What am I missing? I can see the data in the table displaying in the subform, so I would think it would be open. Any help would be greatly appreciated.



    Many thanks!

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Try:
    Code:
    Me.[frmChckOutHist].SetFocus
    DoCmd.GoToRecord , , acNewRec
    Me!Reservation_Date = Date
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    You could omit the line:
    Code:
    Me!Reservation_Date = Date
    and just set the controls Defult Value on the sub form or field in the table instead
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    dhicks is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jun 2017
    Posts
    36
    That seemed to have done the trick, thanks! However, now I am getting error 2465 for the last line of code, saying that Access can't find the field 'Reservation_Date' referred to in the expression. I'm assuming I should be using the field name from the table itself, is that right?

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Try:
    Code:
    Me.[frmChckOutHist].form.Reservation_Date = Date
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    dhicks is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jun 2017
    Posts
    36
    Yes! That did it. I was just missing the "form" part of the syntax. Thanks much to all!!

  7. #7
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    You're welcome. Glad to help
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  8. #8
    dhicks is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jun 2017
    Posts
    36
    I don't want to press my luck here, but I am 99.99% complete with this form except for one line of code. Based on the item selected in the main form, I want the Serial Number field in the subform to match what is displayed in the Main form. Both fields use Short Text data types and hold alphanumeric data. I am getting error 13 Type Mismatch for this line of code"

    Forms!frmChckOutHist!Service_Tag_SN = Service_Tag_SN!Forms!frmLnrLckrInv.Refresh

  9. #9
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Perhaps:
    Code:
    Me.[frmChckOutHist].form.Service_Tag_SN = Me.Service_Tag_SN
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  10. #10
    dhicks is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jun 2017
    Posts
    36
    You are awesome, it's perfect!! Thank you very much!

  11. #11
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by dhicks View Post
    You are awesome, it's perfect!! Thank you very much!
    Thank you for your kind words but as I said before, just happy to help. Having said that, adding to my reputation by clicking on the star at the bottom left would be much appreciated
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  12. #12
    dhicks is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jun 2017
    Posts
    36
    Happy to do it!!

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

Similar Threads

  1. Replies: 2
    Last Post: 01-04-2016, 09:40 AM
  2. Replies: 1
    Last Post: 11-18-2014, 12:35 PM
  3. Replies: 3
    Last Post: 01-23-2014, 07:49 AM
  4. Replies: 0
    Last Post: 07-16-2012, 05:42 AM
  5. Replies: 6
    Last Post: 05-30-2012, 12:32 PM

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