473,804 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA failed query help

lagomorphmom
13 New Member
Hi, I'm a microbiologist but also dabble with many of the computer needs of our little lab. My latest project involves an unfinished database (Access 2000 format, I'm running 2003 on XP PC) inherited from a vendor. Although I've not used Access before, I've been plugged along with the help of our data manager (currently out with hip surgery) and guess I'm an intermediate user now. I do not know VBA although several misc. programming classes (ack in college when Lincoln was a boy) have helped me do what I have needed to so far in that regard, but now I have (I think) a VBA syntax problem I cannot solve.

The problem is with a form which statistically analyzes data pairs. For easier understanding, you can view the form at, http://i55.photobucket .com/albums/g160/lagomorphmom/DeviceReportGen Form_jpg-1.jpg
The large grid square is pretty trick (for me) because clicking on any field produces a query containing the table data for the data pairs in that field - great for editing data. The small table ('Sanity Checks') to the bottom right (in a tempqry made when generating the form) shows single, unmatched data and upon double click, you can see the table data for these results as well. The whole form seems to have been designed in VBA as the only 'build items' are the three clickable buttons on the lower left.

The problem is with the Sanity Checks table - double-click is now unresponsive. It did work originally, and after some troubleshooting , I think the problem was when I had to change the IsolateID column data from number to text format because of number overlap between sites (this made the top data table not work correctly). The code for the unmatched data double-click is:

Expand|Select|Wrap|Line Numbers
  1. Sub SanityDoubleClick()
  2.   Dim ctlList As Control, varItem As Variant
  3.   Dim rslt, IsolateID, Site, qry As String
  4.   Dim intNumColumns, intI As Integer
  5.   Dim qd As QueryDef
  6.   Dim dbs As DAO.Database
  7.  
  8.   On Error Resume Next ' This gets us past the problem of tempQry not existing
  9.   Set dbs = CurrentDb
  10.   Set ctlList = [Screen].ActiveControl
  11.   intNumColumns = ctlList.ColumnCount
  12.   IsolateID = ctlList.Column(0)
  13.   Site = ctlList.Column(1)
  14.   qry = "Select * from MIC_Tbl where IsolateID=" + IsolateID + " and Site = '" + Site + "'"
  15.   DoCmd.DeleteObject acQuery, "_SanityResultQry"
  16.   Set qd = dbs.CreateQueryDef("_SanityResultQry", qry)
  17.   DoCmd.OpenQuery ("_SanityResultQry")
  18. End Sub
I believe his 'On Error next...' line is outdated as both tables generate temp qry's successfully (when IsolateID is numeric). After the Preview button is run, looking in the master query list, the "_SanityResultQ ry" from the last run has been deleted, but the new one does not generate nor obviously open. When IsolateID is text, the upper table still works which is why I thought the problem must be with the "qry =" line sytax above, but I know not what I know not.

Any help here most appreciated, my head hurts! I will be out of the lab until Monday if I've left anything out.
May 10 '07 #1
20 2457
JConsulting
603 Recognized Expert Contributor
Hi, I'm a microbiologist but also dabble with many of the computer needs of our little lab. My latest project involves an unfinished database (Access 2000 format, I'm running 2003 on XP PC) inherited from a vendor. Although I've not used Access before, I've been plugged along with the help of our data manager (currently out with hip surgery) and guess I'm an intermediate user now. I do not know VBA although several misc. programming classes (ack in college when Lincoln was a boy) have helped me do what I have needed to so far in that regard, but now I have (I think) a VBA syntax problem I cannot solve.

The problem is with a form which statistically analyzes data pairs. For easier understanding, you can view the form at, http://i55.photobucket .com/albums/g160/lagomorphmom/DeviceReportGen Form_jpg-1.jpg
The large grid square is pretty trick (for me) because clicking on any field produces a query containing the table data for the data pairs in that field - great for editing data. The small table ('Sanity Checks') to the bottom right (in a tempqry made when generating the form) shows single, unmatched data and upon double click, you can see the table data for these results as well. The whole form seems to have been designed in VBA as the only 'build items' are the three clickable buttons on the lower left.

The problem is with the Sanity Checks table - double-click is now unresponsive. It did work originally, and after some troubleshooting , I think the problem was when I had to change the IsolateID column data from number to text format because of number overlap between sites (this made the top data table not work correctly). The code for the unmatched data double-click is:

Expand|Select|Wrap|Line Numbers
  1. Sub SanityDoubleClick()
  2.   Dim ctlList As Control, varItem As Variant
  3.   Dim rslt, IsolateID, Site, qry As String
  4.   Dim intNumColumns, intI As Integer
  5.   Dim qd As QueryDef
  6.   Dim dbs As DAO.Database
  7.  
  8.   On Error Resume Next ' This gets us past the problem of tempQry not existing
  9.   Set dbs = CurrentDb
  10.   Set ctlList = [Screen].ActiveControl
  11.   intNumColumns = ctlList.ColumnCount
  12.   IsolateID = ctlList.Column(0)
  13.   Site = ctlList.Column(1)
  14.   qry = "Select * from MIC_Tbl where IsolateID=" + IsolateID + " and Site = '" + Site + "'"
  15.   DoCmd.DeleteObject acQuery, "_SanityResultQry"
  16.   Set qd = dbs.CreateQueryDef("_SanityResultQry", qry)
  17.   DoCmd.OpenQuery ("_SanityResultQry")
  18. End Sub
I believe his 'On Error next...' line is outdated as both tables generate temp qry's successfully (when IsolateID is numeric). After the Preview button is run, looking in the master query list, the "_SanityResultQ ry" from the last run has been deleted, but the new one does not generate nor obviously open. When IsolateID is text, the upper table still works which is why I thought the problem must be with the "qry =" line sytax above, but I know not what I know not.

Any help here most appreciated, my head hurts! I will be out of the lab until Monday if I've left anything out.

Change this line
J

Expand|Select|Wrap|Line Numbers
  1.   qry = "Select * from MIC_Tbl where IsolateID='" & IsolateID & "' and Site = '" & Site & "';"
  2.  
  3.  
May 11 '07 #2
lagomorphmom
13 New Member
Thanks, J, for helping. I plugged in the new "qry=...". That lead to a "Run Time Error 94: Incorrect use of Null" in the following function, I highlighted the line the debugger stops at with bold... Again, help here is really appreciated!!!

Expand|Select|Wrap|Line Numbers
  1. Function IsDataInsane(AllBugs As Boolean) As Boolean
  2.   Dim dbs As DAO.Database
  3.   Dim rst As DAO.Recordset
  4.   Dim qry, rsltStr, aStr As String
  5.   IsDataInsane = False
  6.   SanityCheck.OnDblClick = "SanityDoubleClick"
  7.   SanityCheck.RowSource = ""
  8.   aStr = "IsolateID;Site;Record Count"
  9.   SanityCheck.AddItem (aStr)
  10.   Set dbs = CurrentDb
  11.  
  12.   If (AllBugs) Then
  13.     qry = BuildHistogramQry(True, True)
  14.   Else
  15.     qry = BuildHistogramQry(False, True)
  16.   End If
  17.  
  18.   Set rst = dbs.OpenRecordset(qry)
  19.   SCCount.Value = "(" + CStr(rst.RecordCount) + ")"
  20.   If (rst.RecordCount > 0) Then
  21.     IsDataInsane = True
  22.   Else
  23.     Exit Function
  24.   End If
  25.   rst.MoveFirst
  26.   Do While Not rst.EOF
  27.     SanityCheck.AddItem (CStr(rst!IsolateID) + ";" & rst!Site & ";" & CStr(rst!madness))
  28.     rst.MoveNext
  29.   Loop
  30.   SanityCheck.Value = rsltStr
  31. End Function
May 14 '07 #3
Denburt
1,356 Recognized Expert Top Contributor
One of the following is probably a null value. I did not see any checks to prevent this and if you use cstr() on a null value you will get this error, so here is one method.

Expand|Select|Wrap|Line Numbers
  1. SanityCheck.AddItem (CStr(NZ(rst!IsolateID,"")) + ";" & NZ(rst!Site,"") & ";" & CStr(NZ(rst!madness,"")))
Good luck hope it helps.
May 14 '07 #4
JConsulting
603 Recognized Expert Contributor
Thanks, J, for helping. I plugged in the new "qry=...". That lead to a "Run Time Error 94: Incorrect use of Null" in the following function, I highlighted the line the debugger stops at with bold... Again, help here is really appreciated!!!

Expand|Select|Wrap|Line Numbers
  1. Function IsDataInsane(AllBugs As Boolean) As Boolean
  2. Dim dbs As DAO.Database
  3. Dim rst As DAO.Recordset
  4. Dim qry, rsltStr, aStr As String
  5. IsDataInsane = False
  6. SanityCheck.OnDblClick = "SanityDoubleClick"
  7. SanityCheck.RowSource = ""
  8. aStr = "IsolateID;Site;Record Count"
  9. SanityCheck.AddItem (aStr)
  10. Set dbs = CurrentDb
  11.  
  12. If (AllBugs) Then
  13. qry = BuildHistogramQry(True, True)
  14. Else
  15. qry = BuildHistogramQry(False, True)
  16. End If
  17.  
  18. Set rst = dbs.OpenRecordset(qry)
  19. SCCount.Value = "(" + CStr(rst.RecordCount) + ")"
  20. If (rst.RecordCount > 0) Then
  21. IsDataInsane = True
  22. Else
  23. Exit Function
  24. End If
  25. rst.MoveFirst
  26. Do While Not rst.EOF
  27. SanityCheck.AddItem (CStr(rst!IsolateID) + ";" & rst!Site & ";" & CStr(rst!madness))
  28. rst.MoveNext
  29. Loop
  30. SanityCheck.Value = rsltStr
  31. End Function

Expand|Select|Wrap|Line Numbers
  1. Sub SanityDoubleClick()
  2. Dim ctlList As control, varItem As Variant
  3. Dim rslt, IsolateID, Site, qry As String
  4. Dim intNumColumns, intI As Integer
  5. Dim qd As QueryDef
  6. Dim dbs As DAO.DataBase
  7.  
  8. On Error Resume Next ' This gets us past the problem of tempQry not existing
  9. Set dbs = CurrentDb
  10. Set ctlList = [Screen].ActiveControl
  11. intNumColumns = ctlList.ColumnCount
  12. If Nz(ctlList.Column(0), "") = "" Or Nz(ctlList.Column(1), "") = "" Then
  13. MsgBox " You must select an item from the List"
  14. Exit Sub
  15. 'qry = "Select * from MIC_Tbl;" '<--Uncomment to return all records
  16. Else
  17. IsolateID = ctlList.Column(0)
  18. Site = ctlList.Column(1)
  19. qry = "Select * from MIC_Tbl where IsolateID='" & IsolateID & "' and Site = '" & Site & "';"
  20. End If
  21. DoCmd.DeleteObject acQuery, "_SanityResultQry"
  22. Set qd = dbs.CreateQueryDef("_SanityResultQry", qry)
  23. DoCmd.OpenQuery ("_SanityResultQry")
  24. End Sub
  25.  
May 14 '07 #5
lagomorphmom
13 New Member
One of the following is probably a null value.
My bad. I'm really sorry, the null issue is a 'null issue'. I had been testing with a master data table in which I had changed the IsolateID text format back to numbers (and thus taken out all of the alpha-numeric values (but not their records)) so I had empty fields in this column and forgot to switch back to the complete table.

So back to J's answer: that did help, "_SanityResultQ ry" is now generated again with the format for IsolateID as text!

But, the qry is empty (in the picture example, by double clicking on the first line in the Sanity Checks, the qry should have two records containing the data pairs for "1026_MSI") . In Design View, the qry is two columns, "IsolateID" and "Site" with the criteria in this case of "1026" and "MSI", if that helps.
May 14 '07 #6
lagomorphmom
13 New Member
[code]
'qry = "Select * from MIC_Tbl;" '<--Uncomment to return all records
I know not what I know not about that. I can say that when it was working, it only returned the unmatched (unpaired) records.
May 14 '07 #7
JConsulting
603 Recognized Expert Contributor
My bad. I'm really sorry, the null issue is a 'null issue'. I had been testing with a master data table in which I had changed the IsolateID text format back to numbers (and thus taken out all of the alpha-numeric values (but not their records)) so I had empty fields in this column and forgot to switch back to the complete table.

So back to J's answer: that did help, "_SanityResultQ ry" is now generated again with the format for IsolateID as text!

But, the qry is empty (in the picture example, by double clicking on the first line in the Sanity Checks, the qry should have two records containing the data pairs for "1026_MSI") . In Design View, the qry is two columns, "IsolateID" and "Site" with the criteria in this case of "1026" and "MSI", if that helps.
if the value in IsolateID is numeric then you just need to take the tick marks out from around it in the SQL statement

ie

qry = "Select * from MIC_Tbl where IsolateID=" & IsolateID & " and Site = '" & Site & "';"
May 14 '07 #8
JConsulting
603 Recognized Expert Contributor
I know not what I know not about that. I can say that when it was working, it only returned the unmatched (unpaired) records.
I did not know what you wanted to do if the values were null...so I gave the code a message box and an exit...so it wouldn't return anything except a message to the user. I left the sql line there commented in case you wanted to return ALL records from that table. Testing for null, you either return the user to step 1 telling him what he did wrong, or you consider the choice to NOT select is valid, and return everything.
J
May 14 '07 #9
lagomorphmom
13 New Member
if the value in IsolateID is numeric then you just need to take the tick marks out from around it in the SQL statement
No, you were correct, it is text (it was numeric but I had to change it to text to resolve duplicate IsolateID numbers from multiple sites; when I changed to text, I broke the Sanity Checks table).

DoubleClick is now fixed enough to generate the qry, the problem is that it doesn't fill the qry with all records whose IsolateID number matches that of the double-clicked line in the Sanity Checks result table, NOR does it take the next step to open the qry.

I just had a childhood flashback, "Are we almost there yet???" Arggg!
Thanks!
May 14 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
6404
by: Morgan Leppink | last post by:
Hey all - We are running SQL 2000 with ALL available service packs, etc. applied. We just built a brand new database server, which has dual 2Ghz XEONs, 2GB memory, and the following disk configuration: RAID 1 array (2 disks) Operating System Windows Server 2003 RAID 1 array (2 disks) Database Logs RAID 10 array (4 disks) Database Data
1
4160
by: VBSponge | last post by:
Hi all. Need help here as I cant see whats wrong... I have a querydef in Access 2k which execs a stored proc in a SQL Server 2k db. I keep getting the following error, and cant stop it for the life of me: "Error 3146: ODBC Call Failed" Now, the stored proc uses @RETURN_VALUE to pass back an integer result
7
13408
by: Mark | last post by:
Hello, I have researched and tried every thing I have found on the web, in groups and MS KB articles. Here is what I have. I have a Windows 2000 Domain Controller all service packs and every thing else from windows update. ..NET 1.0 and 1.1 installed on the server. Actually .NET was installed before the server was made a DC.
0
2696
by: Arif | last post by:
In my C# application all queries runs well both with MS Access and SQL Server databses. But only the following query runs well on SLQ Server2000 but with MS Access gives error => "IErrorInfo.GetDescription failed with E_FAIL(0x80004005)." QUERY: " SELECT "+ " (select Quantity from Items_Detail idt "+
7
2743
by: Juris Krumins | last post by:
I have a problem with postgresql tables. periodicaly, I would say frequently about 5-10 time per hour i have such errors in my server log file: 2004-04-14 12:23:32 ERROR: cache lookup of relation 149064743 failed 2004-04-14 12:23:32 ERROR: Relation "tmp_table1" does not exist 2004-04-14 12:23:32 ERROR: Relation "tmp_table1" does not exist So turn on debugging options and have that's what i got:
6
2694
by: ruben | last post by:
Hi: I'm running a large database on PostgreSQL 7.1.3. 20 days ago the database failed with a threatening and not too descriptive error like: pg_exec() query failed: server closed the connection unexpectedlyThis probably means the server terminated abnormally before or while processing the request. I lost some data and had to recreate a table, without knowing the reason
4
1231
by: Rex the Strange | last post by:
Hi All, Help please! I have a formview on my page and I've created an update command of the form: "update set valuex=@valuex, valuey=@valuey where valuez=@valuez" which I can get to execute....sort of. The problem is, if it failed I want to know exactly what the database was trying to execute but all I
1
2854
by: imnewtoaccess | last post by:
Hi, SELECT TK_TURN_DAILY_DETAIL1.DATE, TK_TURN_DAILY_DETAIL1.USH_REVENUE AS TDL_Revenue, TK_TCK_SALE_DETAILS1.USH_REVENUE AS TSD_Revenue, - AS Expr1, TK_TCK_SALE_DETAILS1.TK_SERIAL AS TSD_TK_SERIAL, TK_TURN_DAILY_DETAIL1.TK_SERIAL AS TDL_TK_SERIAL, TK_TCK_SALE_DETAILS1.QTY_TIX_REP AS TSD_Quantity, TK_TURN_DAILY_DETAIL1.TCK_SCAN_QTY AS TDL_Quantity FROM TK_TCK_SALE_DETAILS1 RIGHT JOIN (TK_TURN_DAILY_DETAIL1 INNER JOIN TK_IMPORT_TICKET1 ON...
2
6675
by: kilo | last post by:
Hey.. I need someone hwo can help me making my sql table.. I have no php skills. I have payed for a php program that shoud make dictation for people that have some problems reading danish.. with sound and text.. When I'm making the dictation with PHP I'm getting an error like this.: Query failed (SELECT word FROM repository): Table 'test_dig_dk.repository' doesn't exist the first one of the php, that I soud use for makeing the text is.. ...
7
5298
jinalpatel
by: jinalpatel | last post by:
I have 4 tables in SQL 2000. I linked them in MS ACCESS 2003. One of the table is parent table havinf personal information. The other table stores Licenses. One person can have multiple license. I created a query which joins both Parent and Child tables. In a datasheet view of this query if I add any record it will populate both the child and parent. This works fine. I created a form which is bound to this query. I have two commands on this...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10354
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10359
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6870
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.