VBA questions arising from previous post

  • Thread starter Thread starter Tamara
  • Start date Start date
T

Tamara

Hi
This is a question about some VBA code that I was
recommended to add to a form by Kevin in a previous post
(displayed below).

1)
When I add "dim db as database" and "dim qdf1 as
querydef" I get a compile error that database and
querydef are not defined. I thought this may have
something to do with add-ins not being installed but when
I reinstalled access, no add-ins were there to install.

2)
What is the sql string that I have to put here.
sqlStr1 = sqlstring to append conferenceID and
contactID to tableConferenceAttendees

3)
What is me! in the following?
with me!comboboxName

Thanks in advance

Tamara


dim db as database
dim qdf1 as querydef
dim sqlStr1 as string
dim itemSelected as integer

dim conferenceID as Long
.....

set db=currentdb

with me!comboboxName

for itemSelected = 0 to .Listcount-1 'combobox listcount
is 0 based
if(.selected(itemSelected))then
sqlStr1 = sqlstring to append conferenceID and
contactID to tableConferenceAttendees
set qdf1 = db.createquerydef ("",sqlStr1)
qdf1.execute

if(qdf1.recordsAffected=0)then
msgBox "There has been an error, contact the
database administrator for assistance",vbOKOnly
endif
...
end if
next itemSelected

end with
 
Hi Tamara,

1. In the VBA window, select References from the Tools menu and make sure
the Microsoft Access x.x Object Library is selected.

2. The best way to figure out the SQL string you need is to actually create
a similar query in Access and switch to the SQL view of the query. This
will give you a good idea of how the different SQL directives work.

3. The me! object references the form in which the code resides. For
example, if the form name is frmMyForm, then the reference in the form
module could be me!MyControl or frmMyForm!MyControl and either would work.

Hope this helps,
- Glen
 
Back
Top