GoToRecord stopped working during Form_Load()

Anonymous
2022-07-25T14:54:36+00:00

TL;DR - I want to inputbox("What recordID") then doCmd to go to that ID. It was working fine, then it stopped and I can't make it work again. error is 2046 DoCmd isn't available right now. Now idea why.

Private Sub Form_Load()

myRecord = InputBox("What's the recordID?")

DoCmd.GoToRecord , , acGoTo, myRecord

End Sub

This worked for the first hour or so I was working. Eventually after I added a command button for SOME REASON it stopped working. I deleted the button. Still won't work. Nothing I do will make it work and I've been playing with such a small stupid thing for like 30 minutes. Needless to say, I am not a programmer by trade or passion - this is just something that I know needs to be done at work and no one else knows how to do it. Searching the internet, the only thing I can think of is that the records aren't editable except I've checked both w/ the design form gui and programmatically that they're editable and they are. I'm completely at a loss. Sorry for the dumb question - I'm sure it's something simple, but not being able to figure it out is stopping me from working.

Edit: Even if I put in (for example) a command button using the built in functionality to go to the first/last/next/etc. record, the button doesn't do anything. All of this worked before; I have no idea what changed it. I did not touch the form_load() code at all; I wasn't even working on that when it broke.

Microsoft 365 and Office | Access | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
ScottGem 68,840 Reputation points Volunteer Moderator
2022-08-08T18:32:10+00:00

There are a couple of different ways to do this. You can navigate to a specific record by using the navigation buttons at the bottom of the form. But that can be cumberson.

Most developers wil use some sort of search facility to postion the form at the record they want to see. The combobox wizard can create such a search combo (the third option). You can further customize it after the wizard does it's job by modifying the Rowsource. The key is the code the wizard generates to position the form at the selected record. Another method is to create a search form to find the record then open another form filtered for the record you want.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

57 additional answers

Sort by: Most helpful
  1. Anonymous
    2022-07-25T18:38:07+00:00

    Ugh maybe I'm in over my head. I just want to take a moment to thank you again for your tutelage. I did almost this exact same thing ten years ago at another job almost completely in VBA and it was super easy... start to finish was like 30 minutes. I have no idea why I'm having so much trouble now.

    So I tried the combobox idea you had on a new form. I used the wizard, it worked fine. I then added other pertinent fields using the "insert existing data" function. So here's the problem - when the combo box changes, the other fields don't. I think they aren't changing records when the combobox does, but I don't understand why. At the heart of this entire thing is the fact that I can't get the fields to tie themselves to the record like they were when I first started. I've seriously considered deleting this db and just making another one - everything was going fine until I put that command button in and I can do the same thing programmatically w/o using. Idk why this is so difficult. Anyway, here's the algorithm for what I was trying to do:

    What I want to do: Make a db that I can use to track and update grant proposals.

    What I tried;

    1. Make a table with the pertinent data --> done
    2. Make two forms
      1. A form to allow the user to create a new grant record without going into the table, b/c I won't be the only one using it
        1. I did this in design view. It worked as expected.
      2. A form to allow the user to look up (and edit if necessary) records
        1. This requires two things
          1. Locating the correct record
            1. This ideally would be done by entering the PI into a combobox and then picking the due date from a dropdown based on your previous feedback, but originally I did it with a unique ID I called the SIROID
          2. A save, cancel, delete, and new record button, the latter of which would of course go to the form referenced in 1)

    The last time I was playing w/ Access was 10-15 years ago and this was a VERY simple task. Literally it would've taken me longer to decide what to put into the table than it would've to complete something this basic. It boggles my mind that this has taken me more this long and it's still not working - especially given that it was working fine until I tried to add the button.

    For the first form, I created a form in design view. Originally - and this worked perfectly - I just went up to the "insert existing data" button at the top and dragged over every field I wanted to use. Whenever that form was selected, it automatically created a new record using DoCmd. I have absolutely no idea why this stopped working. I didn't change anything on this form. It stopped working at the same time DoCmd stopped working for Form_Load() on the other form though.

    For the second form, I did the same general thing - insert existing data using the button at the top. At that time, I was using an autogenerated number as an index and querying the user to give me that number. When they gave it to me, it automatically pulled up the correct record. All fields correctly populated and were updateable. Everything worked perfectly.

    At this point I decided to add an button for some extra functionality.

    Literally everything stopped working.

    I have been trying to understand why for literally two hours now and I'm ready to throw away my computer and track this stuff in a notebook like they did in the 50s.

    The principle investigator dropdown originally listed the dropdown for this particular record (don't ask me why it started on this record instead of the first one). When I went into it, it's empty. I have another one that I did using the wizard; it works, but when it changes none of the other fields change with it.

    Man I just can't tell you enough how much you appreciate taking this much time helping out someone that has no idea what they're doing. I know I'd figure it out eventually without help, but whether or not I've thrown my PC out the window by that time is another story. From what I hear, the university doesn't like it when you throw expensive hardware out of windows (plus there are potentially students below this office), so I figured I'd give up googling and just ask before I got myself fired lol.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2022-07-25T17:40:32+00:00

    It's like I unaffiliated all forms with the table they're drawing from. (No, I didn't rename the table by accident; I've checked like 10x). This is so frustrating =/

    The first thing to check is the form's RecordSource property.  This should be the name of the table, or of a query based on the table, or the SQL statement for such a query.  If either of the latter you should be able to click on the build button (to the right of the property with three dots), which will take you to design view of the query, from which you would be able to switch to datasheet view to see what rows are returned.

    As regards a navigational combo box you might like to take a look at DatabaseBasics.zip in my same OneDrive folder.  In the section on 'retrieving data from the database' the fourth form in the section includes an unbound combo box in the header, whose RowSource property concatenates the name of the contact with values from other columns to enable contacts of the same name to be differentiated.  You might be able to do something similar.

    If you decide to stick with the ID as the means of going to a record the combo box control wizard will enable you to build such a control if you select the option in the wizard to use the value of the control later rather than save it to a field.  You then just have to put code like the following in its AfterUpdate event procedure:

        Me.[SIRO ID].SetFocus

       DoCmd.FindRecord Nz(Me.[NameOfTheComboBoxGoesHere], 0)

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2022-07-25T16:37:11+00:00

    Thanks so much for your response. I can't believe I can't solve such a simple problem. I have no idea how it started...

    First, I really have to wonder if there is not some combination of fields that uniquely identify a record. If there are a lot of fields that might be the same, then your table needs better normalization.

    Professor + due date would do it honestly. If I can get my fields to stop being #Name or (New) and uneditable I'll try that.

    You should be able to use a combobox or Listbox to be able to select the record from data rather than remembering a Record ID.

    This makes a lot more sense than what I'm doing tbh; Ken recommended this as well, but I run into the same problem. The combobox is empty; there's no dropdown. All fields are empty and uneditable.

    Second, the Expr1000 indicates that you may have a field twice inthe RecordSource of the form. Check the Recordsource, Please let us know what it is.

    Finally, I would not use DoCmd.GotoRecord. That is old VBA code. Instead, I would either create a Filter

    There are no duplicates. Maybe it's b/c it autonumbers? Idk. It's not overly concerning - I was just hoping it led to a Eureka from someone. Given that two people have noted that I probably don't need that unique ID, I've deleted that line. I'm going to use Professor + Due Date to uniquely identify a record.

    Me.Filter = "SIROID = " & Me.controlname

    DoCmd.acCmdApplyFilterSort

    Or use a bookmark

    It didn't understand Me.controlname (but I might be misunderstanding where to put that; I inserted into the Form_Load() code in place of the docmd bit).

    Thanks again for your response! This community is built different... imagine just spending your free time helping other people do things. You guys are awesome!

    Was this answer helpful?

    0 comments No comments
  4. ScottGem 68,840 Reputation points Volunteer Moderator
    2022-07-25T16:14:02+00:00

    First, I really have to wonder if there is not some combination of fields that uniquely identify a record. If there are a lot of fields that might be the same, then your table needs better normalization.

    You should be able to use a combobox or Listbox to be able to select the record from data rather than remembering a Record ID.

    Second, the Expr1000 indicates that you may have a field twice inthe RecordSource of the form. Check the Recordsource, Please let us know what it is.

    Finally, I would not use DoCmd.GotoRecord. That is old VBA code. Instead, I would either create a Filter

    Me.Filter = "SIROID = " & Me.controlname

    DoCmd.acCmdApplyFilterSort

    Or use a bookmark

    Was this answer helpful?

    0 comments No comments