473,386 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Error when executing SQL statment


whenever I run the following code I get an error saying that 'Trade Show
and Conference Contacts database could not find the form 'Events_Form'
referred to in a macro or in Visual Basic Code. The code I am running in
the On_Click event of a button is as follows:

--Code Start--

Private Sub cmdAddTeams_Click()
On Error GoTo Err_cmdAddTeams_Click
Dim VarItem As Variant, SpecStr As String, strSQL As String
Dim strEventID As String, strYear As String
strEventID = ""
strYear = ""
'Both the Event ID and the Year are passed to this form as open
arguments separated by a : (colon)
If Not IsNull(Me.OpenArgs) Then 'Strip out the eventID and the
EventYear
strEventID = Left$(Me.OpenArgs, InStr(1, Me.OpenArgs, ":") - 1)
'Strip out the Event ID
strYear = Right$(Me.OpenArgs, Len(Me.OpenArgs) - InStr(1,
Me.OpenArgs, ":")) 'Strip out the Year
Else
FormattedMsgBox "Error: This form needs to be opened through
code", vbCritical, "Error!"
DoCmd.Close
End If
'This for loop iterates through each of the selected items in the
Teams List and
'adds each tem to the Teams by Year by Event Table and then
populates the
'lstTeams Listbox on the Events Form with the teams that were
selected.
For Each VarItem In lstTeams.ItemsSelected
strSQL = "Insert Into [Teams by Year by Event
Table](EventID,TeamID,EventYear) "
strSQL = strSQL & " VALUES (" & strEventID & "," &
lstTeams.Column(0, VarItem) & ", " & strYear & ");"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL 'add the selected teams to the event
DoCmd.SetWarnings True
DoCmd.Close
--> Forms!Events_Form!lstTeams.Requery

Next VarItem

Exit_cmdAddTeams_Click:
Exit Sub

Err_cmdAddTeams_Click:
FormattedMsgBox Err.Description
Resume Exit_cmdAddTeams_Click
End Sub

--Code End--

the line with the arrow next to it is where the error must be occurring
because it is the only place in the code where I refer to the Events
Form explicitly. Please note that the code does what it is supposed to
do but it always gives that error.

Thank you

Colin


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
2 1337
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It appears that the ListBox you are Requerying is on the same form as
the VBA module. That means you can refer to it this way:

Me!lstTeams.Requery

"Me" refers to the form the VBA code module is attached to.

Another thing - you have a requery inside a loop. It would be better
programming logic to put the Requery after the loop. This will make
the loop run faster, and, once you've updated the ListBox's
Recordsource data, the ListBox only needs to be Requeried once.

HTH,

MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP9Yz5IechKqOuFEgEQLOJQCdGaidARJORvIgetnOEjHtFP OYEcMAoK/5
MxyJH7iganD6JXzAgqBD25d6
=jEcN
-----END PGP SIGNATURE-----

ColinWard wrote:
whenever I run the following code I get an error saying that 'Trade Show
and Conference Contacts database could not find the form 'Events_Form'
referred to in a macro or in Visual Basic Code. The code I am running in
the On_Click event of a button is as follows:

--Code Start--

Private Sub cmdAddTeams_Click()
On Error GoTo Err_cmdAddTeams_Click
Dim VarItem As Variant, SpecStr As String, strSQL As String
Dim strEventID As String, strYear As String
strEventID = ""
strYear = ""
'Both the Event ID and the Year are passed to this form as open
arguments separated by a : (colon)
If Not IsNull(Me.OpenArgs) Then 'Strip out the eventID and the
EventYear
strEventID = Left$(Me.OpenArgs, InStr(1, Me.OpenArgs, ":") - 1)
'Strip out the Event ID
strYear = Right$(Me.OpenArgs, Len(Me.OpenArgs) - InStr(1,
Me.OpenArgs, ":")) 'Strip out the Year
Else
FormattedMsgBox "Error: This form needs to be opened through
code", vbCritical, "Error!"
DoCmd.Close
End If
'This for loop iterates through each of the selected items in the
Teams List and
'adds each tem to the Teams by Year by Event Table and then
populates the
'lstTeams Listbox on the Events Form with the teams that were
selected.
For Each VarItem In lstTeams.ItemsSelected
strSQL = "Insert Into [Teams by Year by Event
Table](EventID,TeamID,EventYear) "
strSQL = strSQL & " VALUES (" & strEventID & "," &
lstTeams.Column(0, VarItem) & ", " & strYear & ");"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL 'add the selected teams to the event
DoCmd.SetWarnings True
DoCmd.Close
--> Forms!Events_Form!lstTeams.Requery

Next VarItem

Exit_cmdAddTeams_Click:
Exit Sub

Err_cmdAddTeams_Click:
FormattedMsgBox Err.Description
Resume Exit_cmdAddTeams_Click
End Sub

--Code End--

the line with the arrow next to it is where the error must be occurring
because it is the only place in the code where I refer to the Events
Form explicitly. Please note that the code does what it is supposed to
do but it always gives that error.

Thank you

Colin


Nov 12 '05 #2
"OnClick event of a button" doesn't tell us what Form that button is in. If
the button is in "Events_Form", then, of course, you just closed it before
referring to it (with the "DoCmd.Close"). If not, perhaps you would clarify
for us.

Larry Linson
Microsoft Access MVP

Forms!Events_Form!lstTeams.Requery"
"ColinWard" <je*********@hotmail.com> wrote in message
news:3f*********************@news.frii.net...

whenever I run the following code I get an error saying that 'Trade Show
and Conference Contacts database could not find the form 'Events_Form'
referred to in a macro or in Visual Basic Code. The code I am running in
the On_Click event of a button is as follows:

--Code Start--

Private Sub cmdAddTeams_Click()
On Error GoTo Err_cmdAddTeams_Click
Dim VarItem As Variant, SpecStr As String, strSQL As String
Dim strEventID As String, strYear As String
strEventID = ""
strYear = ""
'Both the Event ID and the Year are passed to this form as open
arguments separated by a : (colon)
If Not IsNull(Me.OpenArgs) Then 'Strip out the eventID and the
EventYear
strEventID = Left$(Me.OpenArgs, InStr(1, Me.OpenArgs, ":") - 1)
'Strip out the Event ID
strYear = Right$(Me.OpenArgs, Len(Me.OpenArgs) - InStr(1,
Me.OpenArgs, ":")) 'Strip out the Year
Else
FormattedMsgBox "Error: This form needs to be opened through
code", vbCritical, "Error!"
DoCmd.Close
End If
'This for loop iterates through each of the selected items in the
Teams List and
'adds each tem to the Teams by Year by Event Table and then
populates the
'lstTeams Listbox on the Events Form with the teams that were
selected.
For Each VarItem In lstTeams.ItemsSelected
strSQL = "Insert Into [Teams by Year by Event
Table](EventID,TeamID,EventYear) "
strSQL = strSQL & " VALUES (" & strEventID & "," &
lstTeams.Column(0, VarItem) & ", " & strYear & ");"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL 'add the selected teams to the event
DoCmd.SetWarnings True
DoCmd.Close
--> Forms!Events_Form!lstTeams.Requery

Next VarItem

Exit_cmdAddTeams_Click:
Exit Sub

Err_cmdAddTeams_Click:
FormattedMsgBox Err.Description
Resume Exit_cmdAddTeams_Click
End Sub

--Code End--

the line with the arrow next to it is where the error must be occurring
because it is the only place in the code where I refer to the Events
Form explicitly. Please note that the code does what it is supposed to
do but it always gives that error.

Thank you

Colin


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Naren | last post by:
Hi, I am a newbie to Oracle and stored procedures. Hence this question comes up. The complete scenario is like this. We have a multithreaded application using pthreads on HP-UX machine. We are...
0
by: NOSPAM | last post by:
Guys, I get the 'There was an error executing the command' error message. I an using win xp & Access 2002. I created a database using the MS Access template 'Order Entry' I have entered...
8
by: Equilibrium | last post by:
what did I wrong with the program ? (use VC++) /* Using if statment, relational operators, and equality operators */ #include<stdio.h> int main() { printf("Enter two integers, and I will...
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As...
1
by: llee | last post by:
Error message says: Syntax error (missing operator) in query expression. When I click on the debug button, it highlights the line I bolded below ( qryDef.SQL = strSQL & " " & strWhere & "" &...
11
by: Tempo | last post by:
Hello. I am getting the error that is displayed below, and I know exactly why it occurs. I posted some of my program's code below, and if you look at it you will see that the error terminates the...
0
by: wugon.net | last post by:
Hi , Anyone know how to monitor db2 trigger activity ? We suffer some trigger issue today and we try to monitor trigger's behavior use event monitor and db2audit, but both tools can not get...
15
by: Dave | last post by:
I am getting the error above intermittantly with an ASP 3.0 page using an MS Access 2003 database. I have searched Google extensively and found the following possible causes for this error: A...
8
by: slb813 | last post by:
Hello, I am having a problem that I can't seem to work out. I am running Apache 2.2 on a Windows XP platform, using PHP5. I am attempting to insert a row into a MS Access data base with a PHP...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.