Dlookup

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can i first say thanks for all the help i have recieved so far from here.

i am new to VBA so please bear with me!!

I am trying to use the Dlookup function to populate an email from the
current form, i have had no problems using the current form. i also want to
pull data from a subform which is where i am having difficulties

The main form is Attendees, the subform is Attendee Subform

Attendee Subform get data from Events Table

i want EventName from the Subform,

i came up with this

DLookup("EventName", "Events",_ "[EventName]='" & Form![Attendee
Subform]![EventName]& "'")

it gives an error

can any one help
 
if you're running the DLookup() function from within the subform's module,
then the syntax to refer to the control on the subform would be
Me!EventName

if you're running DLookup() from the main form's module, the syntax would be
Me!NameOfSubformCONTROL!EventName

make sure you're using the name of the subform control on the main form, NOT
the name of the subform object in the database window. sometimes the two
names are the same, sometimes not. to get the correct name, open the main
form in design view. click once on the subform (within the main form design
view) to select it. in the Properties box, click on the Other tab and look
at the Name property.

hth
 
Thanks a lot i changed the code to

DLookup("[EventName]", "Events", _
"[EventName] = '" & _
Me![Attendees Subform]![EventName] & "'") & _

and it worked great

tina said:
if you're running the DLookup() function from within the subform's module,
then the syntax to refer to the control on the subform would be
Me!EventName

if you're running DLookup() from the main form's module, the syntax would be
Me!NameOfSubformCONTROL!EventName

make sure you're using the name of the subform control on the main form, NOT
the name of the subform object in the database window. sometimes the two
names are the same, sometimes not. to get the correct name, open the main
form in design view. click once on the subform (within the main form design
view) to select it. in the Properties box, click on the Other tab and look
at the Name property.

hth


Phil said:
Can i first say thanks for all the help i have recieved so far from here.

i am new to VBA so please bear with me!!

I am trying to use the Dlookup function to populate an email from the
current form, i have had no problems using the current form. i also want to
pull data from a subform which is where i am having difficulties

The main form is Attendees, the subform is Attendee Subform

Attendee Subform get data from Events Table

i want EventName from the Subform,

i came up with this

DLookup("EventName", "Events",_ "[EventName]='" & Form![Attendee
Subform]![EventName]& "'")

it gives an error

can any one help
 
The fully qualified reference to a control on a subform is
Form![formName]![subformName].form![controlName] so you'll need to
change Form![Attendee Subform]![EventName] to
Form![yourMainFormName]![Attendee Subform].Form![EventName] assuming
that Attendee Subform is the name of the subform.
 
The fully qualified reference to a control on a subform is
Form![formName]![subformName].form![controlName]

almost. you need to reference the Forms collection as
Forms!

in a VBA module, it usually isn't necessary to use the full reference,
especially when referring to a subform control from the subform's parent
form. i normally use the short reference
Me!NameOfSubformCONTROL!ControlOnSubform
and only expand it if the short reference doesn't run for some reason.

hth


David C. Holley said:
The fully qualified reference to a control on a subform is
Form![formName]![subformName].form![controlName] so you'll need to
change Form![Attendee Subform]![EventName] to
Form![yourMainFormName]![Attendee Subform].Form![EventName] assuming
that Attendee Subform is the name of the subform.
Can i first say thanks for all the help i have recieved so far from here.

i am new to VBA so please bear with me!!

I am trying to use the Dlookup function to populate an email from the
current form, i have had no problems using the current form. i also want to
pull data from a subform which is where i am having difficulties

The main form is Attendees, the subform is Attendee Subform

Attendee Subform get data from Events Table

i want EventName from the Subform,

i came up with this

DLookup("EventName", "Events",_ "[EventName]='" & Form![Attendee
Subform]![EventName]& "'")

it gives an error

can any one help
 
you're welcome :)


Phil said:
Thanks a lot i changed the code to

DLookup("[EventName]", "Events", _
"[EventName] = '" & _
Me![Attendees Subform]![EventName] & "'") & _

and it worked great

tina said:
if you're running the DLookup() function from within the subform's module,
then the syntax to refer to the control on the subform would be
Me!EventName

if you're running DLookup() from the main form's module, the syntax would be
Me!NameOfSubformCONTROL!EventName

make sure you're using the name of the subform control on the main form, NOT
the name of the subform object in the database window. sometimes the two
names are the same, sometimes not. to get the correct name, open the main
form in design view. click once on the subform (within the main form design
view) to select it. in the Properties box, click on the Other tab and look
at the Name property.

hth


Phil said:
Can i first say thanks for all the help i have recieved so far from here.

i am new to VBA so please bear with me!!

I am trying to use the Dlookup function to populate an email from the
current form, i have had no problems using the current form. i also
want
to
pull data from a subform which is where i am having difficulties

The main form is Attendees, the subform is Attendee Subform

Attendee Subform get data from Events Table

i want EventName from the Subform,

i came up with this

DLookup("EventName", "Events",_ "[EventName]='" & Form![Attendee
Subform]![EventName]& "'")

it gives an error

can any one help
 
Back
Top