473,426 Members | 1,591 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,426 software developers and data experts.

Subform RecordSource Error 3008

thelonelyghost
109 100+
Just searched google and this website but I couldn't come up with an answer to this.

Basic Information
Software: Microsoft Access 2000
OS: Windows XP Professional SP3
Problem: Error 3008 (locked table, [tblReturnLog]) when trying to modify recordsource of subform.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSearch_Click()
  2.  
  3. 'Changes recordsource of subform. subform name: frmSubform
  4. ' subform source form: [frmTEMP2]
  5. Me.frmSubForm.Form.RecordSource = BuildSQLStr
  6.  
  7. End Sub
BuildSQLStr is a function that I've debugged and it's working correctly. It outputs a string containing a SELECT statement with WHERE conditions. Before anyone objects, I need it to be formatted this way (as opposed to using filters) to address potential bandwidth issues.

What am I doing wrong? The parent form, a filter form, is bound to a different table and only a combo box reads the field names of the locked table, thereby enabling an ORDER BY option for the results of the filter. Let me know if there's any more info that you need.
Jun 29 '10
57 8143
thelonelyghost
109 100+
@NeoPa:

That depends. Controls are not actually dates as such, even though they can contain data that represents dates. If you absolutely know that it will always be formatted that way, then you needn't format it again. The formatting is important for date/time data which, although it may display in various ways, is actually stored as a real number. The important thing at the end of it is just that the string of characters in your SQL string is formatted correctly. Does that make sense?
I see what you mean, and I'll have to figure out a way to ensure it stays in the MM/DD/YYYY format on the form. I'm familiar with the date being stored as a real number on if the datatype is date/time, but as you said, it only matters if the SQL string is formatted correctly.

I had planned to post this (Debugging in VBA) earlier but I'm not sure I did now.
You did post that earlier. If not on this thread, then on one of the other ones I started. I read through that before and concluded (after little more than a glance) that it was a description of the debugging tool, not instructions on how to use it or the frame of mind needed to do the necessary debugging. I'm looking through it again now because that judgement seems a bit harsh when compared to the quality of your other guides. It's probably just that I missed something.

EDIT: I found an example. In the section about the Watch Pane it talks about the functionality existing, not about how to use it. This isn't the only example available either.
Jul 2 '10 #51
NeoPa
32,556 Expert Mod 16PB
You're quite right. I'm afraid that the full scope of debugging seemed a little much. Covering all the bases could have taken just too long.

What I did do, or more precisely my intention was to, outline the framework available there so that anyone with any previous debugging experience could find themselves at home quite quickly. There are probably as many debugging techniques as there are developers, so explaining How to Debug was not something I felt was too appropriate. I have my particular way of doing things, but that may not suit all.

If you follow the Watch Pane link, then open this up in your own project, you will be able to use the Right-Click menu to see some of the items introduced. I would hope that this would give you a starting point from where you could be aware of, and explore, the facilities available to you.

If the whole concept is foreign to you though, I'm happy to answer specific questions related to the article. Feel free to create a related thread and direct me to it. I will help where I can and will probably add bits into the article as and when it seems appropriate.
Jul 2 '10 #52
thelonelyghost
109 100+
Project update: After much debugging and more help from the community, I've come to realize that my use of filters would not affect the network traffic (bandwidth) the same as if I used recordsource only. After successfully debugging the SQL, I injected it into the WHERE section of a SQL SELECT statement and set that as the recordsource. On startup, the form loads 5-10 seconds faster when referencing a table on the local machine, leading me to believe it'll be that much faster in a client/server setting.

I will post my sourcecode w/ documentation here if I get a chance. Doing this should ensure others won't have to stumble nearly as much as I did. Thanks everybody!
Jul 9 '10 #53
patjones
931 Expert 512MB
@thelonelyghost
I'm really glad to hear it. You'll find that it cuts down on the amount of coding that you have to do as well. Definitely post your final results when you have a chance!

Pat
Jul 12 '10 #54
thelonelyghost
109 100+
I finally have a compilation of the source code for the application I've been using. You do have to edit some of the code to fit to your situation, but that info lies between the labels "Begin User Settings" and "End User Settings", located at the beginning of SQLFilter() and BuildSQLStr(). Let me know if anyone has any questions, comments, or suggestions for the code. I'm more than willing to help!

Note: The Access 2000 Replace() workaround is purely optional. If Replace() works on your version of Access, fix its application on line 15 of SQLFilter().

Disclaimer: This disclaimer is not to be modified or removed except when the source appears in any Visual Basic console. The following code is not to be sold at any price and will be distributed freely and without discrimination. Please refer to the latest copy of the General Public License (currently version 3.0) at http://www.gnu.org/copyleft/gpl.html for further disclaimer.

"lib" Module:
Transformation function in module "lib" for inputs on form:
Expand|Select|Wrap|Line Numbers
  1. Public Function FormToSQL(strField As Variant, strValue As Variant, strDelim As Variant, strOperator As Variant) As String 
  2.  
  3.   If strValue = "''" Or strValue = "" Or IsNull(strValue) Then 
  4.   Exit Function 
  5.   Else 
  6.     strValue = Trim(strValue) 
  7.     If strValue Like "##/##/####" Then 'Normally determines if value is a date, but LIKE shouldn't be used with dates anyway. 
  8.       strValue = "#" & strValue & "#" 
  9.     Else: If Not IsNumeric(strValue) Then strValue = "'" & strValue & "'" 
  10.     End If
  11.  
  12. 'Combines inputs for 
  13.       Select Case strOperator
  14.     Case "EQ"
  15.       strOperator = " = "
  16.     Case "GT"
  17.       strOperator = " >= "
  18.     Case "LT"
  19.       strOperator = " <= "
  20.     Case "LK"
  21.       strOperator = " LIKE "
  22.     Case Else
  23.       Exit Function
  24.       End Select
  25.  
  26.     FormToSQL = strDelim & "[" & strField & "]" & strOperator & strValue 
  27.  
  28.   End If 
  29.  
  30. End Function
.
Only needed if using Access 2000 (see above note):
Expand|Select|Wrap|Line Numbers
  1. '*********Access 2000 Replace() Workaround*********
  2. Public Function StrReplace(strHaystack As String, strNeedle As String, strReplaceWith As String, intRepeat As Integer) As String
  3.  
  4. Dim init As Long, i As Integer
  5.  
  6. If Len(strHaystack) < 1 Or Len(strNeedle) < 1 Or intRepeat > 0 = False Then 'Failsafe for illegal inputs
  7.     Exit Function
  8. Else 'General declarations of variables
  9.   init = InStr(strHaystack, strNeedle)
  10.   i = intRepeat
  11. End If
  12.  
  13. Do While init > 0 And i > 0
  14.   strHaystack = Left(strHaystack, init - 1) & strReplaceWith & Right(strHaystack, Len(strHaystack) - Len(strNeedle) - init + 1)
  15.  
  16.   'Maintenance for While-loop
  17.   i = i - 1
  18.   init = InStr(strHaystack, strNeedle)
  19. Loop
  20.  
  21. StrReplace = strHaystack
  22.  
  23. End Function
.
Form's Module:
Header:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. '**********Begin User Settings**********
  4. 'total number of control boxes that are related to the fields being queried
  5. Private Const numberOfInputs = 8
  6. '**********End User Settings**********
  7.  
  8. Private aFld(1 To 2, 1 To numberOfInputs) As String, aVal(1 To numberOfInputs) As Variant, aOp(1 To numberOfInputs) As String
  9. Private strTableName As String
Transforming a form's inputs into one string of SQL for filter (SQLFilter) or SELECT application (BuildSQLStr):
Expand|Select|Wrap|Line Numbers
  1. '************Creates Filtering criteria in SQL syntax************
  2. Private Function SQLFilter() As String
  3.  
  4. Dim strSQLContent As String, strDelim As String
  5.  
  6. 'Dim aFld(1 To numberOfInputs) As String, aVal(1 To numberOfInputs) As Variant, aOp(1 To numberOfInputs) As String
  7.  
  8. '******************Field Names, Control Sources, and Operators******************
  9. '****************Begin User Settings****************
  10. 'Sets the associated table of all field names to strTableName by default
  11. For i = 1 To numberOfInputs
  12.   aFld(1, i) = strTableName
  13. Next
  14.  
  15. '********Notes********
  16. 'aFld : name of the field in [tblReturnLog]
  17. 'aVal : value of the field to look for in [tblReturnLog]
  18. ' aOp : abbreviation of operator in SQL, i.e. "LK" = LIKE
  19. '*********************
  20. aFld(2, 1) = "OldLogNumber"
  21. aVal(1) = Me.txtOldLogNumber
  22.  aOp(1) = "LK"
  23. aFld(2, 2) = "CTSLogNumber"
  24. aVal(2) = Me.intCTSLogNumber
  25.  aOp(2) = "LK"
  26. aFld(2, 3) = "ReportSentTo"
  27. aVal(3) = Me.txtReportSentTo
  28.  aOp(3) = "LK"
  29. aFld(2, 4) = "CustomerPartNumber"
  30. aVal(4) = Me.txtCustomerPartNumber
  31.  aOp(4) = "LK"
  32. aFld(2, 5) = "DateReceived"
  33. aVal(5) = Format(Me.dtMinDateR, "MM/DD/YYYY")
  34.  aOp(5) = "GT"
  35. aFld(2, 6) = "DateReceived"
  36. aVal(6) = Format(Me.dtMaxDateR, "MM/DD/YYYY")
  37.  aOp(6) = "LT"
  38. aFld(2, 7) = "CompletionDate"
  39. aVal(7) = Format(Me.dtMinDateClosed, "MM/DD/YYYY")
  40.  aOp(7) = "GT"
  41. aFld(2, 8) = "CompletionDate"
  42. aVal(8) = Format(Me.dtMinDateClosed, "MM/DD/YYYY")
  43.  aOp(8) = "LT"
  44.  
  45. 'detecting whether to use AND or OR
  46. 'based on button 'ANY' or 'ALL'
  47.   strDelim = IIf(Me.btn2SearchSettingsAnyAll = 1, " OR ", " AND ")
  48. '****************End User Settings****************
  49.  
  50. 'transforming form inputs into SQL code with subfunction
  51. For i = 1 To numberOfInputs
  52.   strSQLContent = strSQLContent & lib.FormToSQL(aFld(2, i), aVal(i), strDelim, aOp(i))
  53. Next
  54.  
  55. 'Clean up the concatenation of all of the fields into a SQL statement fragment
  56. SQLFilter = lib.StrReplace(strSQLContent, strDelim, "", 1)
  57.  
  58. End Function
Expand|Select|Wrap|Line Numbers
  1. '*********Builds SELECT statement in SQL*********
  2. Private Function BuildSQLStr() As String
  3.  
  4. Dim strSQLFilter As Variant, strFieldNames As String
  5.  
  6. '*********Begin User Settings*********
  7. strTableName = "tblReturnLog" 'Sets the name of the table to a global variable
  8. '*********End User Settings*********
  9.  
  10.  
  11. strSQLFilter = SQLFilter 'Optimization: calculates value of SQLFilter once
  12.  
  13. 'Lists all field names and associated tables in SQL format.  Useful if JOIN is used.
  14. For i = 1 To numberOfInputs
  15.   strFieldNames = strFieldNames & "[" & aFld(1, i) & "].[" & aFld(2, i) & "], "
  16. Next
  17. strFieldNames = Left(strFieldNames, Len(strFieldNames) - 2)
  18.  
  19. 'Overall: builds SELECT statement from User Settings
  20. 'Line 1: lists the specific name of each column/field to be referenced, opening up ability to allow JOIN
  21. 'Line 2: lists criteria to filter by, if there are any
  22. BuildSQLStr = "SELECT " & strFieldNames & " FROM [" & strTableName & "]" & _
  23.                IIf(Len(strSQLFilter) > 0, " WHERE " & strSQLFilter & ";", ";")
  24.  
  25. End Function
Jul 16 '10 #55
patjones
931 Expert 512MB
I am happy to see that you got it all sorted out; and thanks for posting your solution. Too often, people just never respond as to what worked or what didn't work, diminishing the thread's value.

One small suggestion I have is that you can easily combine GreaterThanAttachedAnd, LessThanAttachedAnd, LikeAttachedAnd into one function. They are all the same except for the comparison operator, so I would simply make one function, put an argument in that allows the user to indicate what comparison they want to perform, and then pick the respective operator using a Case statement or whatever logic structure you prefer.

Pat
Jul 16 '10 #56
thelonelyghost
109 100+
Successful testing resulted in me posting the revised code above. I also modified all dependencies on the old code to fit with the revision.
Jul 16 '10 #57
thelonelyghost
109 100+
This leads into an idea for further revision. I'm looking at using a For-each loop in SQLFilter() for FormToSQL() and setting up three arrays (arrFieldName, arrValue, arrOperator). Does anyone know if this would actually optimize the code, or would it just look prettier?

EDIT: Just did some major code revision to carry out this idea and make it easier to implement JOINs in SELECT statement.
Jul 16 '10 #58

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

Similar topics

5
by: ColinWard | last post by:
Hi. I have a contacts form with an unbound dropdown box and a bunch of bound controls relating to the contact. When I load the form, I want all the controls to be empty until I select a name from...
0
by: Lauren Quantrell | last post by:
I'm using SQL Server backend on an Access 2K front end. I populate a subform: Forms!myForm.myChild.Form.RecordSource = "myStoredProcedureName" On that form is a control where the controlsource is...
4
by: Peter Bailey | last post by:
I have a subform that I dont want to have a recordsource initially as it is locking the table that is created dynamically. I want to connect to the table after the data has been written by another...
0
by: robert.waters | last post by:
Hello, Say that there is a database for client information; there is a main form that displays the client's name, and this form has one or more subforms that display different types of...
13
by: bitsnbytes64 | last post by:
Hi, I have a form which contains a subform. Both are were creetd using the form wizard and are bound by the column IXO_NR (on two different tables), which is the control source for a textbox on...
6
by: Widge | last post by:
I'm having a nightmare. I've used this technique before and can't understand why I'm getting an error using it now. Basically I have a form, on that is a sub form datasheet. What I am eventually...
7
by: tnjarrett | last post by:
Hello, I have a MS Access continuous subform that was using a query as the recordsource. I changed it to use a recordset instead because when the query was used, the changes to the subform values...
2
stonward
by: stonward | last post by:
I'm trying to change the recordsource of a subform using a simple button click: by default, the subform's source is one query, when a button is clicked it changes to another query (the same query,...
7
reginaldmerritt
by: reginaldmerritt | last post by:
Has anyone had this problem before, my search on-line would suggest it not common but I'm sure you fine folk will be able to help. This is the code I have used to change the recordsource on a...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.