Populate control with query result

Hello, I have a textbox on a form that I would like to populate with the results of a query. I would like this to happen when a form opens.

If it helps this is my query

SELECT Max([DMR Tracking].[DMR#]+1) AS myDMR
FROM [DMR Tracking];

I'm new to access and have a form to create a new record. This form when loaded does not know the last defalutId of the previous record. I thought that I can get the last record and get the next value to populate the textbox.

Any help is appreciated!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In VBA, in the current event of the form:

Private Sub Form_Current()

If me.newrecord = true then
Me.TextBoxName = DLookup("myDMR", "MyQueryName")
end if

end sub

Open in new window

(You'll have to replace Textboxname and MyQueryName with the real names as used in your database)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gogetsomeAuthor Commented:
Thanks for helping!

I'm getting a compile error: Method or data member not found

is my code which is in the form load event

Private Sub Form_Load()

Dim stDocName As String

    DoCmd.Echo False
    DoCmd.GoToRecord , , acNewRec
    If Me.NewRecord = True Then
Me.DMR# = DLookup("myDMR", "GetNextDMRID")
End If

    DoCmd.GoToControl "DMR#"
    DoCmd.Echo True

End Sub
Try renaming your control to not include the #.

txtDMRNumber is a safe and standard convention for a text box.
gogetsomeAuthor Commented:
Changing the control name broke some macros and such> I will get in touch once I fix those errors. Thanks for your Help. I will return.
gogetsomeAuthor Commented:
Thank you for your assistance. I was able to overcome my issues. WOW I inherited a mess :-) One more bug off the list.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.