Selecting Individual reom Record With VB

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Please could you look at the following discusstion I had
with an expert individual. Unfortunately I still have
difficulty with the suggestion and if anybody coudl shine
light on the matter, it would be greatly appreciated.

I dont understand what is asked with the field name being
passed over and the concatenation. If you could please
read the discussion we had, starting from the bottom and
explain and/or list an example please, it would be
greatly appreciated. I bit off a bit more than I could
chew, and when I understnad this, I'll be in the clear.

I'd like to thank Wayne for his contribution.

Thankx

Paul
-----Original Message-----
DoCmd.OpenForm stDocName2,,,"[FieldName]=" & MemberVar

You need to pass the field name also and concatenate in the value of
MemberVar. The above will work if MemberVar is a
number,
if it is text try:
DoCmd.OpenForm stDocName2,,,"[FieldName]='" & MemberVar & "'"

This will work as long as there are no values that have apostrophes (i.e.
O'Rielly) in them. If there are, let me know and I'll change it to work with
that.

This is being passed as the WhereCondition. Note the commas as place holders
for the unused options prior to the last used one.

--
Wayne Morgan
Microsoft Access MVP


I need to, with VB code, open a form and display a
specific record.

For a test example, I am have a variable
called "MemberVar" and would like to open a form using
the variable.

I already hae the following which dont work:

DoCmd.OpenForm stDocName2, , MemberVal, MemberVal

"StDocName2" represents the name of the form I want to
open.
I put "MemberVar" in twice because I dont know if they
are or are not suppsoed to be in or either.

As you can see, Im quite stupid, and a little light on
this matter would be greatly appreciated. Thnakx

Paul
 
Paul,

Here is an example pulled right out of online help from
access:

The following example opens the Employees form in Form
view and displays only records with King in the LastName
field.

DoCmd.OpenForm "Employees", , ,"LastName = 'King'"

LastName is a field on the form Employees. You must have
a field on your form that you are trying to use to
retrieve information based on MemberVal.

"LastName = 'King'" <-- This is like saying select all
records where LastName = 'King'

Wayne told you to use:

DoCmd.OpenForm stDocName2,,,"[FieldName]=" & MemberVar

[FieldName] is the field on your form that you would use
to retrieve your data, based on what gets keyed into it.
In this case, MemberVal is the variable representing what
you want to find.

If you had a form to retrieve information about a person,
you might have a field on your form called SSN, for social
security number (at least in the US). MemberVar would be
the ssn, for example 123456789. So you would have a
command like:

DoCmd.OpenForm Personform,,,"[SSN]=123456789"

Of course, you don't want to hard code a social security
number. That's why you concatenate a variable, which
contains the information.

Try looking up OpenForm Method in online help. It might
help a little more. Wish I could make this clearer for
you.
-----Original Message-----
Please could you look at the following discusstion I had
with an expert individual. Unfortunately I still have
difficulty with the suggestion and if anybody coudl shine
light on the matter, it would be greatly appreciated.

I dont understand what is asked with the field name being
passed over and the concatenation. If you could please
read the discussion we had, starting from the bottom and
explain and/or list an example please, it would be
greatly appreciated. I bit off a bit more than I could
chew, and when I understnad this, I'll be in the clear.

I'd like to thank Wayne for his contribution.

Thankx

Paul
-----Original Message-----
DoCmd.OpenForm stDocName2,,,"[FieldName]=" & MemberVar

You need to pass the field name also and concatenate in the value of
MemberVar. The above will work if MemberVar is a
number,
if it is text try:
DoCmd.OpenForm stDocName2,,,"[FieldName]='" & MemberVar & "'"

This will work as long as there are no values that have apostrophes (i.e.
O'Rielly) in them. If there are, let me know and I'll change it to work with
that.

This is being passed as the WhereCondition. Note the commas as place holders
for the unused options prior to the last used one.

--
Wayne Morgan
Microsoft Access MVP


I need to, with VB code, open a form and display a
specific record.

For a test example, I am have a variable
called "MemberVar" and would like to open a form using
the variable.

I already hae the following which dont work:

DoCmd.OpenForm stDocName2, , MemberVal, MemberVal

"StDocName2" represents the name of the form I want to
open.
I put "MemberVar" in twice because I dont know if they
are or are not suppsoed to be in or either.

As you can see, Im quite stupid, and a little light on
this matter would be greatly appreciated. Thnakx

Paul

.
 
Please could you look at the following discusstion I had
with an expert individual. Unfortunately I still have
difficulty with the suggestion and if anybody coudl shine
light on the matter, it would be greatly appreciated.

I dont understand what is asked with the field name being
passed over and the concatenation.

Wayne cannot see your database. He does not know what the names of the
fields in your table might be.

[FieldName] should be replaced by the name of the field in your table
which contains the Member ID. MemberVar should be a variable
containing the value of that field that you are searching for.

For instance, if you have a field named MemberNo which contains a
numeric member number, and you want to find member 123, then you would
set MemberVar to 123 and use

DoCmd.OpenForm stDocName2,,,"[MemberNo]=" & MemberVar

If, on the other hand, you have a Text field MemberID, you need quote
marks around the value:

DoCmd.OpenForm stDocName2,,,"[MemberID]=;" & MemberVar & "'"
 
Back
Top