![]() | |
![]() |
| | Thread Tools | Display Modes |
#21
| |||
| |||
|
|
PW <emailaddyinsig (AT) ifIremember (DOT) com> wrote in news:056c17lpne67ds7lhgr67kgp8a2ppop1dt (AT) 4ax (DOT) com: On 7 Jul 2011 19:30:14 GMT, "David-W-Fenton" NoEmail (AT) SeeSignature (DOT) invalid> wrote: "Access Developer" <accdevel (AT) gmail (DOT) com> wrote in news:97kdpfF8khU1 (AT) mid (DOT) individual.net: What are you trying to accomplish? We seem to have had a 'rash' of people who 'want' Forms to store/define data, lately, and on that assumption, tell us how they are trying to do something that does not work and want us to help them correct it. We usually can, but only after asking the proper questions and getting them answered. It's usually very difficult to provide a solution when all you've been provided is the non-working solution to the problem, but no description of what the task is that's at hand. I am trying to create an SQL Select string that is based upon what combination of fields the user has selected. But for what purpose? The whole point of my question is that your goal of constructing a SQL string MAY BE THE WRONG WAY TO GO. What are you doing with the SQL string? Is this a query-by-form interface? If so, that's what you need to call it, because then people know what you're trying to do. |
#22
| |||
| |||
|
|
On 10 Jul 2011 01:43:03 GMT, "David-W-Fenton" NoEmail (AT) SeeSignature (DOT) invalid> wrote: PW <emailaddyinsig (AT) ifIremember (DOT) com> wrote in news:056c17lpne67ds7lhgr67kgp8a2ppop1dt (AT) 4ax (DOT) com: On 7 Jul 2011 19:30:14 GMT, "David-W-Fenton" NoEmail (AT) SeeSignature (DOT) invalid> wrote: "Access Developer" <accdevel (AT) gmail (DOT) com> wrote in news:97kdpfF8khU1 (AT) mid (DOT) individual.net: What are you trying to accomplish? We seem to have had a 'rash' of people who 'want' Forms to store/define data, lately, and on that assumption, tell us how they are trying to do something that does not work and want us to help them correct it. We usually can, but only after asking the proper questions and getting them answered. It's usually very difficult to provide a solution when all you've been provided is the non-working solution to the problem, but no description of what the task is that's at hand. I am trying to create an SQL Select string that is based upon what combination of fields the user has selected. But for what purpose? The whole point of my question is that your goal of constructing a SQL string MAY BE THE WRONG WAY TO GO. What are you doing with the SQL string? Is this a query-by-form interface? If so, that's what you need to call it, because then people know what you're trying to do. I think that is exactly what I am trying to do David. A sort of data mining form for querying our Access database where the user can select any combination of what they selected for the controls on the form. -paulw |
#23
| |||
| |||
|
|
I think that is exactly what I am trying to do David. A sort of data mining form for querying our Access database where the user can select any combination of what they selected for the controls on the form. |
"
"
"
"
"
"
"
#24
| |||
| |||
|
|
PW <emailaddyinsig (AT) ifIremember (DOT) com> wrote in news:dpqj17dsl1vqilmpp9q4k9953n2tothgfn (AT) 4ax (DOT) com: I think that is exactly what I am trying to do David. A sort of data mining form for querying our Access database where the user can select any combination of what they selected for the controls on the form. Googling "Access query by form" brings back a whole host of possible approaches to the problem. I have had three different approaches over the years: 1. the ad hoc approach -- write the SQL on the fly based on the particulars of the form. 2. use a class module that abstracts the structure so you can use that to write "dumb" code that does all the work for you (but is very hard to use and understand). 3. a hybrid between ad hoc and some form of automatic processing of the results. Mostly, I use #1. |
|
The first thing I do that it's important is decide that any single QBF interface will return only one fixed resultset in all cases. This is very often nothing more than a temp table with a checkbox field and a PK that connects to the main table in the particular app (usually PersonID). The QBF search process simply finds the records that match the requested criteria and appends the PKs to the temp table. The display of results is usually in a subform of the search form, and includes a lot more fields (and the display results can differ depending on the type of search). This makes things relatively easy, as it means the FROM clause of the SQL INSERT statement that populates the temp table is static. So, the only thing that has to be done is to write the WHERE clause. Here's the function that writes it for one of my more recent apps (I haven't fixed the formatting for the SQL strings, which I have unwrapped in the source code): Private Function GetWhere() As String Dim strPersonType As String Dim strTemp As String Dim varItem As Variant Dim strConferences As String Dim strLapsed As String Dim ctl As Control Dim strAttendeeInformation As String Dim strAttendee As String Dim strField As String Dim strCriteria As String Select Case Me!optWho Case 1 strPersonType = "Attendee" Case 2 strPersonType = "Exhibitor" Case 3 strPersonType = "Speaker" Case 4 ' do not filter at all Case 5 strPersonType = "Prospect" End Select If Len(strPersonType) > 0 And strPersonType <> "Prospect" Then strTemp = strTemp & " AND PersonType = " & STR_QUOTE & _ strPersonType & STR_QUOTE End If If (Me!lstConference.ItemsSelected.Count > 0) Then For Each varItem In Me!lstConference.ItemsSelected strConferences = strConferences & ", " & _ Me!lstConference.ItemData(varItem) Next varItem strConferences = Mid(strConferences, 3) strTemp = strTemp & " AND ConferenceID IN (" _ & strConferences & ")" End If If (Me!optLapsed.Enabled) And (Not IsNull(Me!cmbLapsedStart) _ And Not IsNull(Me!cmbLapsedYear)) Then Select Case Me!optWho Case 1, 4 strLapsed = "SELECT DISTINCT tblAttendeeConference.AttendeeID FROM tblConference INNER JOIN tblAttendeeConference ON tblConference.ConferenceID = tblAttendeeConference.ConferenceID WHERE tblAttendeeConference.AttendeeID Not In (SELECT DISTINCT tblAttendeeConference.AttendeeID FROM tblConference INNER JOIN tblAttendeeConference ON tblConference.ConferenceID = tblAttendeeConference.ConferenceID WHERE tblConference.Year>=" & Me!cmbLapsedYear & " "Case 2 strLapsed = "SELECT DISTINCT tblBooth.ExhibitorID FROM tblConference INNER JOIN tblBooth ON tblConference.ConferenceID = tblBooth.ConferenceID WHERE tblBooth.ExhibitorID Not In (SELECT DISTINCT tblBooth.ExhibitorID FROM tblConference INNER JOIN tblBooth ON tblConference.ConferenceID = tblBooth.ConferenceID WHERE tblConference.Year>=" & Me!cmbLapsedYear & " "Case 3 strLapsed = "SELECT DISTINCT tblSpeakerSessions.AttendeeID FROM tblConference INNER JOIN (tblSpeakerSessions INNER JOIN tblSession ON tblSpeakerSessions.SessionID = tblSession.SessionID) ON tblConference.ConferenceID = tblSession.ConferenceID WHERE tblSpeakerSessions.AttendeeID Not In (SELECT DISTINCT tblSpeakerSessions.AttendeeID FROM tblSpeakerSessions INNER JOIN (tblConference INNER JOIN tblSession ON tblConference.ConferenceID = tblSession.ConferenceID) ON tblSpeakerSessions.SessionID = tblSession.SessionID WHERE tblConference.Year>=" & Me!cmbLapsedYear & " "End Select strLapsed = strLapsed & " AND tblConference.Year>" & _ Me!cmbLapsedStart & " And tblConference.Year<" & _ Me!cmbLapsedYear strTemp = strTemp & " AND tblPerson.PersonID IN (" _ & strLapsed & ")" End If Select Case strPersonType Case "Attendee", vbNullString ' eliminate anybody who has ever been an Exhibitor For Each ctl In Me!ctlTab.Pages("pgeAttendees").Controls If ctl.ControlType = acTextBox Then If Not IsNull(ctl) Then If ctl.Name = "txtTypeAttend" Then strField = ("tblAttendeeConference." & _ Mid(ctl.Name, 4)) strCriteria = Replace((Me("txt" & _ Mid(ctl.Name, 4))), ".", "?") strCriteria = Replace(strCriteria, ",", "?") strCriteria = Replace(strCriteria, "+", "?") If Me("cmb" & Mid(ctl.Name, 4)).Column(1) = 0 Then strCriteria = "*" & strCriteria & "*" End If strAttendee = strAttendee & " AND (" & _ Application.BuildCriteria(strField, dbText, _ strCriteria) & ")" Else strField = ("tblAttendeeInformation." & _ Mid(ctl.Name, 4)) strCriteria = Replace((Me("txt" & _ Mid(ctl.Name, 4))), ".", "?") strCriteria = Replace(strCriteria, ",", "?") strCriteria = Replace(strCriteria, "+", "?") strAttendeeInformation = strAttendeeInformation & _ " AND (" & Application.BuildCriteria(strField, _ dbText, strCriteria) & ")" End If End If End If Next ctl Set ctl = Nothing strAttendee = Mid(strAttendee, 6) If Len(strAttendee) > 0 Then strTemp = strTemp & " AND " & strAttendee End If strAttendeeInformation = Mid(strAttendeeInformation, 6) If Len(strAttendeeInformation) > 0 Then strTemp = strTemp & " AND tblPerson.PersonID IN (SELECT DISTINCT tblAttendeeInformation.AttendeeID FROM tblAttendeeInformation WHERE " & strAttendeeInformation & ")" End If Case "Prospect" strTemp = strTemp & " AND tblPerson.PersonID IN (SELECT DISTINCT tblPerson.PersonID FROM (tblPerson LEFT JOIN tblAttendeeConference ON tblPerson.PersonID = tblAttendeeConference.AttendeeID) INNER JOIN tblPersonType ON tblPerson.PersonID = tblPersonType.PersonID WHERE (((tblPersonType.PersonType)='Attendee') AND ((tblAttendeeConference.AttendeeConferenceID) Is Null)) "Case "Exhibitor" Select Case Me!optExhibitors Case 1 strTemp = strTemp & " AND tblPerson.PersonID IN (SELECT DISTINCT tblPerson.PersonID FROM tblPerson INNER JOIN (tblConference INNER JOIN tblBooth ON tblConference.ConferenceID = tblBooth.ConferenceID) ON tblPerson.PersonID = tblBooth.ExhibitorID WHERE (((tblConference.ConferenceID)=" & Me!cmbConference & ")) "Case 2 strTemp = strTemp & " AND tblPerson.PersonID IN (SELECT DISTINCT tblPerson.PersonID FROM (([SELECT DISTINCT tblBooth.ExhibitorID As PersonID FROM tblBooth WHERE (((tblBooth.ConferenceID)=" & GetCurrentConference() & "));]. AS CurrentExhibitors RIGHT JOIN tblPerson ON CurrentExhibitors.PersonID = tblPerson.PersonID) INNER JOIN tblPersonType ON tblPerson.PersonID = tblPersonType.PersonID) INNER JOIN tblBooth ON tblPerson.PersonID = tblBooth.ExhibitorID WHERE (((CurrentExhibitors.PersonID) Is Null) AND ((tblPersonType.PersonType)='Exhibitor') AND ((tblBooth.ConferenceID)<>" & GetCurrentConference() & ")) "Case 3 strTemp = strTemp & " AND tblPerson.PersonID IN (SELECT DISTINCT tblPerson.PersonID FROM (tblPerson LEFT JOIN [SELECT tblBooth.BoothID, tblBooth.ExhibitorID FROM tblBooth WHERE (((tblBooth.ConferenceID)=" & GetCurrentConference() & "));]. AS CurrentBooths ON tblPerson.PersonID = CurrentBooths.ExhibitorID) INNER JOIN tblPersonType ON tblPerson.PersonID = tblPersonType.PersonID WHERE (((CurrentBooths.BoothID) Is Null) AND ((tblPersonType.PersonType)='Exhibitor')) "Case 4 ' All ' do nothing at all -- doesn't change the criteria End Select Case "Speaker" End Select GetWhere = Mid(strTemp, 6) End Function |
#25
| |||
| |||
|
|
Unbound Bob. I got tired of Access automatically saving records (I think that was it. And other stuff maybe). |
#26
| |||
| |||
|
|
On Wednesday, July 6, 2011 7:04:33 PM UTC-5, PW wrote: Unbound Bob. I got tired of Access automatically saving records (I think that was it. And other stuff maybe). Although this is an older post I am responding to, I don't get this "automatically saving records" statement at all. About all that happens is that if you are on a new record and add something to a field it will update the autonumber whether or not the record is saved or canceled. Same thing occurs whether opening the table directly or using a table as a form's recordsource. If one has a love affair with sequential autonumbers that might be of concern but a poor reason to abandon bound controls. Could you describe your issue of automatic saves so that I may become aware of the dangers of bound forms. |
#27
| |||
| |||
|
|
Patrick Finucane wrote: On Wednesday, July 6, 2011 7:04:33 PM UTC-5, PW wrote: Unbound Bob. I got tired of Access automatically saving records (I think that was it. And other stuff maybe). Although this is an older post I am responding to, I don't get this "automatically saving records" statement at all. About all that happens is that if you are on a new record and add something to a field it will update the autonumber whether or not the record is saved or canceled. Same thing occurs whether opening the table directly or using a table as a form's recordsource. If one has a love affair with sequential autonumbers that might be of concern but a poor reason to abandon bound controls. Could you describe your issue of automatic saves so that I may become aware of the dangers of bound forms. I think he's referring to the behavior where navigating to a new/different record automatically saves any changes to the record from which the navigation occurred without warning the user or giving him any chance to change his mind. The user is forced to remember to ctrl-backspace before tabbing or clicking into the next row. Yes, the developer can mitigate this but many think it should be the other way around: the default behavior should be to ask the user if changes should be saved and it should be up to the developer to modify that behavior. I imagine it's similar to the distaste for opt-out vs. opt-in. |
#28
| |||
| |||
|
|
On Thu, 14 Jul 2011 12:54:49 -0400, "Bob Barrows" reb01... (AT) NOyahooSPAM (DOT) com> wrote: Patrick Finucane wrote: On Wednesday, July 6, 2011 7:04:33 PM UTC-5, PW wrote: Unbound Bob. *I got tired of Access automatically saving records (I think that was it. *And other stuff maybe). Although this is an older post I am responding to, I don't get this "automatically saving records" statement at all. *About all that happens is that if you are on a new record and add something to a field it will update the autonumber whether or not the record is saved or canceled. *Same thing occurs whether opening the table directly or using a table as a form's recordsource. If one has a love affair with sequential autonumbers that might be of concern but a poor reason to abandon bound controls. *Could you describe your issue of automatic saves so that I may become aware of the dangers of bound forms. I think he's referring to the behavior where navigating to a new/different record automatically saves any changes to the record from which the navigation occurred without warning the user or giving him any chance to change his mind. The user is forced to remember to ctrl-backspace before tabbing or clicking into the next row. Yes, the developer can mitigate this but many think it should be the other way around: the default behavior should be to ask the user if changes should be saved and it should be up to the developer to modify that behavior. I imagine it's similar to the distaste for opt-out vs. opt-in. I agree Bob! *And yes Patrick, we are concerned about sequential record numbers. *Our clients use reservation numbers for reference, for instance, and I bet some will freak out if there is a gap between them. -paulw- Hide quoted text - - Show quoted text - |
#29
| |||
| |||
|
|
but a poor reason to abandon bound controls. Could you describe your issue of automatic saves so that I may become aware of the dangers of bound forms. I think he's referring to the behavior where navigating to a new/different record automatically saves any changes to the record from which the navigation occurred without warning the user or giving him any chance to change his mind. The user is forced to remember to ctrl-backspace before tabbing or clicking into the next row. Yes, the developer can mitigate this but many think it should be the other way around: the default behavior should be to ask the user if changes should be saved and it should be up to the developer to modify that behavior. I imagine it's similar to the distaste for opt-out vs. opt-in. I would think a navigation buttons would be irrelevant in an unbound form. Huh? In an unbound form, especially one that displays a single record at a |
|
If you have data that makes the form dirty it will run the BeforeUpdate event thus you can cancel it. |
| This would not be an issue with an unbound form. |
#30
| |||
| |||
|
|
Patrick Finucane wrote: but a poor reason to abandon bound controls. Could you describe your issue of automatic saves so that I may become aware of the dangers of bound forms. I think he's referring to the behavior where navigating to a new/different record automatically saves any changes to the record from which the navigation occurred without warning the user or giving him any chance to change his mind. The user is forced to remember to ctrl-backspace before tabbing or clicking into the next row. Yes, the developer can mitigate this but many think it should be the other way around: the default behavior should be to ask the user if changes should be saved and it should be up to the developer to modify that behavior. I imagine it's similar to the distaste for opt-out vs. opt-in. I would think a navigation buttons would be irrelevant in an unbound form. Huh? In an unbound form, especially one that displays a single record at a time, navigation buttons are not irrelevant. If you have data that makes the form dirty it will run the BeforeUpdate event thus you can cancel it. Well, yeah! In other words, developers are being forced to "opt-out" of the undesirable behavior rather than opting in. This would not be an issue with an unbound form. ... which I think answers your original question.- Hide quoted text - - Show quoted text - |
![]() |
| Thread Tools | |
| Display Modes | |
| |