How do I select a value from a field in an ACCESS unbound datasheet

H Experts,
How do I select a value from a field in an ACCESS unbound datasheet?  My unbound datasheet displays the following fields:  JobID, JobStartDate, JobEndDate, JobAddress.  When  a row/record is selected in the datasheet, I want to put the value of the JobID field in a variable.
I found the following code below, but it only provides the current records position/location in the datasheet (i.e. 1, 2, 3, etc..)

Dim i As Integer
i = Me.dataDisplaySubform.Form.CurrentRecord
MsgBox (CStr(i))

Open in new window


Is it possible to do what I need?  How?  Please provide examples.

Thank you all very much in advance,
mrotor
mainrotorAsked:
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.

Eric ShermanAccountant/DeveloperCommented:
i = Me.dataDisplaySubform.Form!JobID


ET
0

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
PatHartmanCommented:
Your data sheet is bound.  Otherwise it couldn't show more than a single row.

You are referring to the CurrentRecord property, that is why you are getting the record's ordinal number.  If you want to get something from a control, you need to refer to the control name.

Me.SaveJobID = Me.subformname.Form!JobID
0
hnasrCommented:
ET's comment is fine.
Alternative:
i = Me!dataDisplaySubform.Controls("JobID")

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Nick67Commented:
Your answer is already given.
You were close, but .CurrentRecord is a property that gives you a number related to your position in the records of an object.  If you had 20 records showing and the cursor is in a control in the ninth row, .CurrentRecord would give you '9'

But your syntax is good up to that point

Dim i As Integer
i = Me.dataDisplaySubform.Form
.CurrentRecord
MsgBox (CStr(i))

Where it gets tricky is after the Form
! operators vs . operators is not well understood (and maybe not even by me -- we'll see if I get corrected here :)
The ! operator gives you the members of a collection
The . operator gives you the properties of an object
Sometimes these two things overlap (Controls are one area of overlap.  Each control is a member of the Controls collection, but they are also defined as properties of the Me object)

You only get Intellisense for the . operator and not for the ! operator.
That trips up a lot of folks when it comes to referencing subforms & subreports
The default collection for a form or report is its Controls collection.

So you want the subform's JobID control
Ok
'I = Me | Mysubform control | treat it as a form
i = Me.dataDisplaySubform.Form.Controls("JobID").Value
That's as explicit as it gets
Now, the Controls collection is the default collection for a form
And the Value property is the default property for a control, so
i = Me.dataDisplaySubform.Form!JobID
is the briefest way of writing the syntax.

Hope this helps

Nick67
0
hnasrCommented:
>>! operators vs . : Late binding vs immediate binding

Try this in a any event Sub, say Form_Current with a break point at Private Sub line

Me.s.w = 4   ' this immediate binding, it also allow for intellisense to help in writing code.

When you step into procedures it shows an error on .s unless it happens to have a correct values.
Also this error stops you from using immediate window from checking your code.

But with this

Me!s!w =4  'this is late binding, it checks code when time to execute.

Code highlights then when you press Step into again, it displays an error.
You can use immediate window to check code.
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
How do I select a value from a field in an ACCESS unbound datasheet?
As Pat mentioned here, and I mentioned in your previous question, you're not using an UNBOUND datasheet. If you were, you'd see a single record and nothing more.

I mention this because it's important to use the correct terminology when asking questions like this. An "unbound" form is one that has no Recordsource, and where the controls have no ControlSource. Even if you do not initially "bind" a form to a Recordsource, if you do at some point (and if your controls are bound), then you're using a bound form. In an unbound form, you're entirely responsible for grabbing data from a datasource, and filling the controls. You're further responsible for handling any data edits/additions/deletions. There's rarely a need to do this in Access - and there is never a need in a datasheet form.

If you use the wrong terminology, you run the risk of getting incorrect or misguided advice. In this case, since the participants are all very experienced you don't have much to worry about, but these sorts of things can bite you.

Long story short - be sure you understand the terminology you're using, and make sure you convey that information to the Experts correctly. You'll have a much better EE experience.
0
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.