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. ScottGem 68,840 Reputation points Volunteer Moderator
    2022-07-25T19:36:30+00:00

    Its hard to tell what you did differently without seeing exactly what you did,

    But you are heading down the worng path with your table structure, Your table strucutre should look more like this:

    tblGrants

    GrantID (Primary Key Autonumber)

    GrantName

    GrantDueDate

    GrantScope (text: either I or E

    GrantTypeID (Foreign Key to Research Type lookup table)

    SponsorID (FK to Sponsor table)

    SubSponsorID (FK)

    SponsorGrantID

    GrantMax

    GrantDR

    GrantMaxYears

    GrantReqYears

    GrantTotal

    DateSubmitted

    Notes

    CollegeID (FK to table of colleges)

    You would then need a table of Sponsors, Colleges and ResearchTypes (Research, CSA, etc.)

    You should have 2 tables for PIs

    tblPI

    PIID (PK Autonumber)

    Firstname

    LastName

    other info about PI

    tblPIAssigned

    PIAssignedID (PK Autonumber)

    GrantID (FK)

    PIID (FK)

    Primary (Yes/No)

    Indirect funding and Awards should be in separate tables

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2022-07-25T19:11:52+00:00

    Thanks so much man.

    So the table I made has 20-30ish entries:

    I retried the combo box thing from the wizard and now it's properly changing everything. It wasn't before. I have no idea why; I just deleted the form and made a new one and it worked. From what I can tell, it's b/c Access hates me XD.

    So now the update form looks like this and is working (fingers crossed - this is where I was before I even went online for help like 3-4 hours ago #fml):

    I have absolutely positively no idea why it works now but didn't before. Like none. Zero. I'm so confused.

    I'm going to add all of the fields that aren't up there to this form, then make a second form EXACTLY like this one except when it loads, I'm going to tell it to make a new record when it opens. My plan was to do that with DoCmd.GoToRecord , , acNewRec in form load. If that works, I'm done for today b/c I slotted this to take 1 hr (when I did it last time it took 30 minutes!) and it's turned into an all day project. I'll get back to it either today or tomorrow morning, and when I do I'll update you on whether or not it blew up.

    Was this answer helpful?

    0 comments No comments
  3. ScottGem 68,840 Reputation points Volunteer Moderator
    2022-07-25T18:56:48+00:00

    So other issues. You said; "Make a table with the pertinent data"

    This raises red flags right off the bat. No way a database as you describe should be one table. Just on what you have posted you need a Grants table, a colleges table, an investigators table, a sponsors table and probably more. You probably should read upo on Noirmalization before going further. Befire yiou start designing forms yiou NEED to get your table strucutre squared away.

    Users should NOT directly access tables, You should use forms for all interaction between users and tables,

    When creating forms, I almost always use the Form wizard, rather than dragging and dropping fields onto the form. This makes it easier to properly design the form, thgen customize it to your needs.

    Was this answer helpful?

    0 comments No comments
  4. ScottGem 68,840 Reputation points Volunteer Moderator
    2022-07-25T18:46:21+00:00

    No, you misunderstood me. Ken and I are not saying to not use the Record number to filter records, but you select that record number from a combobox.

    If you create a combobox with the following properties you can use it to select the RecrodID:

    RowSource: SELECT SIROID, Professor, DueDate FROM table ORDER BY Professor, DueDate;

    Bound column: 1

    Column Count: 3

    Column Widths: 0";2";1"

    This will display the professor and due date but when selected, will return the SIROID.

    Another plce you misundertood Is with the Expr1000, this means the feild appears twoce in the recordSOURCE, not thge recordSET. The Recordsource ius where the form piulls the set of records from. If you can post the Recordsource as I asked we can point out the error.

    Finally you don't have fields on a form, you have controls that may or may not be bound to a field in a table. Each control has a Name property that is how you refenrece the control in code. And no, that code does not go in the Form Load event. It would go in the After update event of the combobox.

    Was this answer helpful?

    0 comments No comments