The Right Query String

Jun 5, 2007

Hi all,

My name is Sarah and I'm working with a simple guestbook script that runs with an Access database. Right now the script displays all guestbook entries. I want to alter it so it only displays entries if a given person's name is "Bruce". This might sound goofy but if I can get this functionality then I'll be able to alter the script to build a bunch of simple scripts that I have planned.

Here's the code that displays all entries on the guestbook:

Code:<%'Dimension variablesDim adoCon 'Holds the Database Connection ObjectDim rsGuestbook'Holds the recordset for the records in the databaseDim strSQL'Holds the SQL query for the database'Create an ADO connection odjectSet adoCon = Server.CreateObject("ADODB.Connection")'Set an active connection to the Connection object using a DSN-less connectionadoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")'Set an active connection to the Connection object using DSN connection'adoCon.Open "DSN=guestbook"'Create an ADO recordset objectSet rsGuestbook = Server.CreateObject("ADODB.Recordset")'Initialise the strSQL variable with an SQL statement to query the databasestrSQL = "SELECT tblComments.Name, tblComments.Comments FROM tblComments;"'Open the recordset with the SQL query rsGuestbook.Open strSQL, adoCon'Loop through the recordsetDo While not rsGuestbook.EOF'Write the HTML to display the current record in the recordsetResponse.Write ("<br>")Response.Write (rsGuestbook("Name"))Response.Write ("<br>")Response.Write (rsGuestbook("Comments"))Response.Write ("<br>")'Move to the next record in the recordsetrsGuestbook.MoveNextLoop'Reset server objectsrsGuestbook.CloseSet rsGuestbook = NothingSet adoCon = Nothing%>

My friend told me that I need to alter the query string to something like this, but I can't get it to work:

Code:SELECT tblComments.Name, tblComments.Comments FROM tblComments WHERE tblComments.Name = Bruce ;

As you can tell I'm not a programmer but I can usually alter scripts to get them to do what I want. If I could get this figured this out I would be the happiest woman alive.

Sarah

View Replies


ADVERTISEMENT

Modules & VBA :: Separate Numbers And String From Alpha-numeric String

Jun 7, 2013

MS-Access VBA code to separate numbers and string from an alphanumeric string.

Example:

Source: 598790abcdef2T
Output Required: 598790

Source: 5789065432abcdefghijklT
Output Required: 5789065432

View 13 Replies View Related

Self Generating Query String Based On Query Results?

Jan 3, 2008

Here's my problem. I need to generate a report that says how much of each individual product was produced and as well as the total produced for a specified category in a time period. Something like the following:

05 Catagory A: 02 Product AA, 01 Product AB, 02 Product AC
10 Category B: 07 Product BA, 03 Product BB
04 Category C: 01 Product CA, 01 Product CB, 01 Product CC, 01 Product CD

etc...

I currently have a query that queries a database and pulls out all products that were produced in a specified period and the categories they belong to and dump them into a local access table. Now what I need to do is search through the query results and count up how many of each product were produced (02 AA, 01 AB, etc...) and the totals for each category. The number of categories is pretty limited (6), but there are hundreds of product codes, so I need a way to do this without having to type in each induvidual product code as the requirement by which the query searches. Also, the product codes that get returned are different every day.

I was thinking something along the lines of take the product code of the first row and check for any others in the results that match and write that into another table. Then move onto row 2 and use its product code as a search parameter and search through the query results for any matches. Then continue that until the end of the query results. Can I do that? Is there a better way to achieve what I need?

View 7 Replies View Related

String Validation (string Must Start With Http://)

Mar 12, 2007

Hi all,

I was looking for some help. I am trying to setup a table with a field for web address. People are entering www.website.com etc however I need them to make sure it starts with http:// Is their any way I can put validation on the field to make sure that this is entered? Or maybe I could use an input mask?

Any suggestions would be gratefully recieved.

Andy.

View 3 Replies View Related

Writing A String Into A SQL Query

Mar 5, 2008

i have a string in VB (eg. "test")that will cahnge depending on the input, ihow can i search for the string and display the data into a form?

i currently have this
"SELECT [Tasks].Staff_Name, [Tasks].Project_Title, [Tasks].Percentage_Complete, [Tasks].Tracking_Number FROM [Tasks] WHERE [Tasks].Staff_Name like [forms].[Main].[test] ORDER BY [Tasks].Staff_Name;"



but how can i make it so it spits the data into its corresponding feilds onto a form? (just like it would be if i performed a wizard?)

View 1 Replies View Related

Appending To A String In A Query

Jul 4, 2005

I need to build up a string containing values separated by commas. The following almost does this.

I use an update query in which the "Update to" field for 'String field' contains
[String field] & IIf(Len([String field])<1,"",", ") & [Related table]![Value to append]

I would like to have the [Related table]![Value to append] in ascending order.
I.e. I would like the result to look like "A, B, C, F, H", not "B, C, H, F, A". Any suggestions as to how to apply the sort?

View 1 Replies View Related

How To Get Some Fileld From Query To A String?

Nov 22, 2005

Hey,

Can someone pls tell me how can i get data from query to a string so i can use it in my VBA code?

I have a query that basicly creates me a uniqeu code and i need that code when i write new record in datasheet form? For example:

I have Query1 that has a field1 with data "AASSFF"
Now i need that data in my Table1 field1

THX, S

View 1 Replies View Related

Do I Need Zero Length String Query

Jan 22, 2007

In a database that holds membership records, I have three years worth of info relating to membership dues paid. I want to extract who has not paid a membership fee for the last three years, so we can strike them off our records, i.e. I have members' personal details, but there are no records in the payments table, nothing has been entered because they just have not paid. Do I run a query looking for a zero length string? Just how do I achieve this? Have I done right in not entering anything?

Help appreciated!

View 2 Replies View Related

Need Help Splitting String In Query

Mar 30, 2008

Hey people,

This should be any easy one to solve:

I need to split a field in my query into two separate fields, e.g fullname into a first and last name, so "John Smith" will appear in two columns, "John" and "Smith".

Thanks in advance.

View 3 Replies View Related

Can A Query Accept Value From A String.

Aug 8, 2006

Can i create a query that will have a string in the Criteria box, where that string is assigned a value in VB code?

for instance:

Dim xyz As String

xyz = "TV"



and I put in the Criteria Box WHERE xyz = "Pizza"

View 4 Replies View Related

Turning Query Results Into String...

Jun 23, 2005

Hello, I have a query that returns a list of courses undertaken by certain employees. They are in the format NPTC CS 30; NPTC CS 31; NPTC 33; NPTC FTC 38; NPTC FTC 40 etc...

Anyway what I need to do with this is convert these results to a string and manipulate them in such a way that they can be displayed in a text box on the back of an ID card in the following format:

NPTC CS 30, 31, 33, NPTC FTC 38, 40... etc.

Because there is not enough room on the back of the ID card to use a subform to just display them in a list...

View 3 Replies View Related

Left Three Characters From String Using Query

Sep 8, 2005

In MySQL I can use the LEFT(3, field_name) command, but I essentially want access to pull all records from a table where the the first three digits of a number field match those pre-selected by a form drop down.

This database is in Access 97. Is there a way to compare the first x number of digits using SQL only, or do I need to run each line through code first, and then check it (I really don't want to do that)?


example numbe rin field:

123456789

SQL checks to see if 123 matches value selected on a form.

View 1 Replies View Related

Query Field String Too Long

Mar 8, 2006

Let's say I have a query like:

select [x]+[y] as A, [z]*[A] as B from MyTable.

I have found that sometimes this works and sometimes it doesn't, (Like, it works the first time I run it, but later quits working....)so I've gotten into the habit of repeating my calculations and writing it thus instead:

select [x]+[y] as A, [z]*([x]+[y]) as B from MyTable.

However, I now have some query fields that have so many calculations in them that I exceed the string length that Access allows for a query field. So is there a way to make the shorter SQL work consistently?

Any ideas appreciated.

Thanks!

PS: Here's the field I need to shorten:
AdjFcstDay: IIf(((Sum([AvgDaily])*First([forecastweeks])*5+nz(First([backlog]),0))/(First([forecastweeks])*5))+IIf([wiptotal]<(IIf(First(CDbl(nz([dailystddev],0)))<=0,0,xlnormsinv(First([lowwipflag]))*First([dailystddev]))),((IIf(First(CDbl(nz([dailystddev],0)))<=0,0,xlnormsinv(First([lowwipflag]))*First([dailystddev])))-[wiptotal])/5,IIf([wiptotal]>(IIf(First(CDbl(nz([dailystddev],0)))<=0,0,xlnormsinv(First([highwipflag]))*First([dailystddev]))),((IIf(First(CDbl(nz([dailystddev],0)))<=0,0,xlnormsinv(First([highwipflag]))*First([dailystddev])))-[wiptotal])/5,0))<0,0,(Sum([AvgDaily])*First([forecastweeks])*5+nz(First([backlog]),0))+IIf([wiptotal]<(IIf(First(CDbl(nz([dailystddev],0)))<=0,0,xlnormsinv(First([lowwipflag]))*First([dailystddev]))),((IIf(First(CDbl(nz([dailystddev],0)))<=0,0,xlnormsinv(First([lowwipflag]))*First([dailystddev])))-[wiptotal])/5,IIf([wiptotal]>(IIf(First(CDbl(nz([dailystddev],0)))<=0,0,xlnormsinv(First([highwipflag]))*First([dailystddev]))),((IIf(First(CDbl(nz([dailystddev],0)))<=0,0,xlnormsinv(First([highwipflag]))*First([dailystddev])))-[wiptotal])/5,0)))

View 1 Replies View Related

Remove Comma From String In Query

Mar 8, 2006

I have this query:

INSERT INTO 1_2_06 ( Issue_ID, Assigned_To, ListType )
SELECT Issue_ID, Assigned_To, 'QPT'
FROM QPTActions
WHERE QPTActions.Entry_Date<=DateValue('1/2/2006') And QPTActions.Close_Date>DateValue('1/2/2006');

The Assigned_To values are a Lastname, Firstname format as they come out of the first database. But I need the comma stripped before they get entered into the INSERT database. Is it possible to do this on the fly?

View 2 Replies View Related

Query Based On String Value In List

Apr 8, 2008

Hello again.

I have a drop-down list that contains string values. Is it possible to construct a query that will sum the total number of times that the string value is selected? For example,

String Value Sum
================
Chicken 3
Beef 9
Pork 2


I have been trying to work on this for a while and cannot figure it out. Can someone shed some light on this issue? Thanks.

View 1 Replies View Related

Capture Raw SQL Query String To Form

Aug 24, 2007

Hello everyone,

Simply put, I want to create a form to which I can enter a raw SQL statement (such as: SELECT * FROM contacts without having to create a new Access query.

The way i have tried to do this is by creating a form which uses an onclick function to pass the string variable (the query statement) to a sencond form and have the second form run the statement. I can pass the variable ok but I cant figure out how to the use the variable string in the second form to execute as the "Record Source" of the form.

Any ideas?

Thanks,
Curveo

View 7 Replies View Related

Modules & VBA :: Result From A Query To Specify String To Use

Jun 7, 2015

I have a query that returns the string to use but I am not sure how I can actually use the returned value to do what I want.

e.g.
my table:
Partner ID Backup Field
5023949 UPC
501354 GTIN

my query will return 1 [backup field] value from the table above, and I then want to use that value to get another value that was previously declared in my code.

eg
GTIN = "ABC123"
UPC = "123ABC"

if my query returns the value "GTIN" then need to use the value of GTIN (ABC123) in my next part of the code.

msgbox GTIN would result in a message box ABC123

But I am not sure how to get the result value. I can say msgbox [backup field] but that returns "GTIN" not "ABC123"

View 14 Replies View Related

General :: How To Get Last Character Of The String In Query

Nov 5, 2012

How to get the last character of the string in query?

I have a table name PlateNo and I want to get the last character for registration purposes.

Ex. ZMD-123 - I want to get the number three(3) and if its possible every time the user types the last digit in criteria it will show all plate number ending in the entered number.

View 5 Replies View Related

Queries :: Parameters To Query String

Aug 15, 2014

Do access VBA implements parameters passed to query strings in all following parameters?I've been working in ASP.NET/Razor C# and this would be an example of how it would be done:

Code:
db.Query("INSERT INTO threads (name, date_of_creation, user_id, area_id, user_group_id)" +
" VALUES(@0, @1, @2, @3, @4)",
Request["txtThreadTitle"],
DateTime.Now,
Session["user_id"],
area_id,
0
);

View 6 Replies View Related

Convert String To Date In Query

Jun 21, 2015

I have a string value that comes out of a query in the form of

01012015
02012015
12012014

etc...

where the first 2 digits are the month, the next 2 are the day, and the next 4 are the year.How do I convert these values to a valid date that can be queried on?

View 14 Replies View Related

String Found In *deleted* Query/form

Aug 20, 2007

I've created a function to search for a string in SQL definitions:
Public Sub SearchInQueryDefs(strSearch As String)

Dim qdf As QueryDef
Dim qdfs As QueryDefs
Dim blnFound As Boolean

Set qdfs = CurrentDb.QueryDefs

For Each qdf In qdfs
blnFound = InStr(1, qdf.SQL, strSearch) > 0
If blnFound Then
Debug.Print "Searching : " & qdf.Name & "...";
Debug.Print " - found"
If vbNo = MsgBox("Found!" & vbCrLf & vbCrLf & "" & strSearch & " found in "

& qdf.Name & vbCrLf & vbCrLf & qdf.SQL & "" & vbCrLf & vbCrLf & "Click 'Yeah' to

continue search, 'Duh' to stop", vbExclamation + vbYesNo, "SearchInQueryDefs") Then
Exit Sub
End If
End If
Next qdf

MsgBox "Done searching.", vbInformation, GetAppTitle()
End Sub

Using the following statement (in the immediate window) i get the following result:
SearchInQueryDefs "Queries"
Searching : ~sq_cfrmReports~sq_clstQueries... - found
However query "~sq_cfrmReports~sq_clstQueries" doesn't exist.
It is probably a query which populates the listbox "lstQueries" in the "frmReports"

form. But that form doesn't exist in my database. I have deleted it some time ago. I

thought that Compact and Repair got rid of stuff like this.
I found the definition in the MsysObjects and with this Id also in the MsysQueries.
So my question is obvious: what is this, why is this and what can i do about it?

Thx!

View 6 Replies View Related

Help Passing A Text Box String To A Saved Query

Sep 21, 2005

I have a multi-select list box that runs a "For intCounter" and builds a sting into a text box. That works fine the text box will populate as designed <"Closed" OR "On-Going">.

(I know that I should be dynamically creating the query in the first place ... normally I would ... but this is a quick fix that I want to get it into an existing application, while the redesign requirements are being written.)

Now I want to pass that string to a pre-existing query, but I'm not sure what to write in the criteria section.

I've tried...
Like "*" & [Forms]![ViewReports]![TextPickList] & "*"
IIf([Forms]![ViewReports]![TextPickList]="","",[Forms]![ViewReports]![TextPickList])

and just plain old ...
[Forms]![ViewReports]![TextPickList]

but my query is coming up blank. What do I need to write into the criteria section of this saved query?

thanks in advance!

View 2 Replies View Related

Exporting Dates From Query To Txt File As String

Jan 2, 2007

I have a complex query that I am exporting to a tab delimited text file.

The query has three date fields, and a time field. The query export results in both the date and time portions of the value being shown instead of one or the other.

I have tried using the format function to force the dates to only show the date portion, and the time field to only show the time portion. So far, without luck.

I would greatly appreciate help from someone who can spot what I am doing wrong. The sql for my query is below.


SELECT tblSiteVisits.RunID AS TripID, Format([tblSampleRuns]![RunDate],"mm/dd/yyyy") AS [Trip Start Date], Format([tblSampleRuns]![RunDate],"mm/dd/yyyy") AS [Trip End Date], [RunName] & " " & [tblSampleRuns]![RunDate] AS [Trip Name], "LUMMI001" AS [Project ID], tblSites.SiteNumber AS [Station ID], STORET_SiteVisitNum.VisitNum AS [Station Visit Number], [tblSiteVisits]![SiteVisitID] & "-" & [tblParameters]![Matrix] AS [Activity ID], [tblParameters]![Matrix] AS Medium, Storet_ActivityCategories.Activity_Type AS [Activity Type], Storet_ActivityCategories.[Activity Category], tblSampleData.QCIndicator AS [QC Indicator], STORET_Replicate.RepNo AS [Replicate Number], Format([tblSampleRuns]![RunDate],"mm/dd/yyyy") AS [Activity Start Date], "" & Format([VisitTime],"hh:nn:ss") & "" AS [Activity Start Time], STORET_TimeZoneOutput.TimeDatum AS [Activity Start Time Zone], "" AS [Depth to Activity], "" AS [Depth to Activity Units], tblSiteVisits.SiteComments AS [Activity Comments], Storet_MethodsProcedures.ProcedureID, IIf([LabParam]=-1,"WSWB","") AS [Gear ID], Storet_Characteristics.CharacteristicName, IIf(IsNull([PracticalDetectionLimit]),Str([Value]),IIf([Value]<[PracticalDetectionLimit],"Present < QL",Str([Value]))) AS [Result Value], tblUnits.UnitName AS [Result Value Units], Storet_Fractions.Fraction, "" AS [Result Comment], "" AS Personnel, IIf([tblParameters]![LabParam]=-1,[LabID],"") AS [Laboratory ID], Storet_MethodsProcedures.ProcedureID AS [Field/Lab Procedure], Storet_MethodsProcedures.SourceAcronym AS [Field/Lab Procedure Source], "" AS [Analysis Date], "" AS [Analysis Time], "" AS [Analysis Time Zone], "" AS [Lab Sample Prep Procedure], "" AS [Lab Sample Prep Procedure Source], tblSampleData.PracticalDetectionLimit AS [Detection Limit], tblSampleData.UnitID AS [Detection Limit Unit], "F" AS [Result Status], tblStatisticTypes.StatisticType AS [Statistic Type], IIf(IsNull([tblSampleData]![StatisticTypeID]),"Actual",[ValueType]) AS [Value Type]
FROM ((Storet_StaticFields RIGHT JOIN tblSites ON Storet_StaticFields.StaticFieldID = tblSites.StaticFieldID) RIGHT JOIN ((tblRuns RIGHT JOIN (tblSampleRuns LEFT JOIN STORET_TimeZoneOutput ON (tblSampleRuns.RunDate = STORET_TimeZoneOutput.RunDate) AND (tblSampleRuns.RunID = STORET_TimeZoneOutput.RunID)) ON tblRuns.RunTypeID = tblSampleRuns.RunTypeID) RIGHT JOIN (tblSiteVisits LEFT JOIN STORET_SiteVisitNum ON tblSiteVisits.SiteVisitID = STORET_SiteVisitNum.SiteVisitID) ON tblSampleRuns.RunID = tblSiteVisits.RunID) ON tblSites.SiteID = tblSiteVisits.SiteID) RIGHT JOIN ((Storet_Fractions RIGHT JOIN (Storet_Characteristics RIGHT JOIN tblParameters ON Storet_Characteristics.CharacteristicID = tblParameters.CharacteristicID) ON Storet_Fractions.FractionID = tblParameters.FractionID) RIGHT JOIN (Storet_MethodsProcedures RIGHT JOIN (Storet_ActivityCategories RIGHT JOIN (STORET_Replicate RIGHT JOIN (((tblSampleData LEFT JOIN tblStatisticTypes ON tblSampleData.StatisticTypeID = tblStatisticTypes.StatisticTypeID) INNER JOIN STORET_ActivityType ON tblSampleData.ResultID = STORET_ActivityType.ResultID) LEFT JOIN tblUnits ON tblSampleData.UnitID = tblUnits.UnitID) ON STORET_Replicate.ResultID = tblSampleData.ResultID) ON Storet_ActivityCategories.ID = tblSampleData.Activity_Category) ON Storet_MethodsProcedures.MethodID = tblSampleData.MethodID) ON tblParameters.ParameterID = tblSampleData.ParameterID) ON tblSiteVisits.SiteVisitID = tblSampleData.SiteVisitID
WHERE (((Storet_Characteristics.CharacteristicName) Is Not Null) AND ((IIf(IsNull([PracticalDetectionLimit]),Str([Value]),IIf([Value]<[PracticalDetectionLimit],"Present < QL",Str([Value])))) Is Not Null) AND ((tblSampleRuns.RunDate) Between [forms]![fmExportStoret]![StartExport] And [Forms]![fmExportStoret]![EndExport]) AND ((tblSampleData.SampleStrata)=1 Or (tblSampleData.SampleStrata)=2 Or (tblSampleData.SampleStrata)=3) AND ((tblSampleData.Exported_To_Storet)=[Forms]![fmExportStoret]![ExportType] Or (tblSampleData.Exported_To_Storet)=0));


and the code for the export is

Dim MYPATH As String

MYPATH = CurrentProject.Path & "EXPORTRESULTS" & Format(Date, "mmddyyyy") & ".txt"

DoCmd.TransferText acExportDelim, "STORETEXPORT", "STORET_MSRRESULTS_TABLE2", MYPATH, True



Thanks for taking the time to help :)

View 9 Replies View Related

Help W/ Query String- Combine Multiple Fields

Oct 3, 2007

Hey guys-
I have 2 tables- and need to find the record matches between them via their product code. Table 1 has the code as follows (and is considered 'the Master List')-
xxx-xx-xxx Where x is an integer.

Table 2 has split the 3 sections of the code out to 3 individual fields, like this-
Field1 Field2 Field3
xxx xx xxx

I need a query that will combine the 3 fields in table 2 to the same format as Table1 so that I can find the matches between them. I know this is a basic question, but I'm a learning newbie. How would I write that in a query? I don't think I want to write the format to the table- just include it in the query somehow...
Thanks!

View 6 Replies View Related

Showing A String Query Result In A Subform

Sep 19, 2005

I have a dinamic SQL string built by a function, and i want to assign it to a query to show it in a subform.
Here are the names.

Form FrmServiciosAfectados
Subform subFrmcnsServiciosAfectados
Query cnsServiciosAfectados
Built SQL String strSQLPuertosCanales

Please help me with code.

View 2 Replies View Related

General :: String Fields - Add Next Condition To Query

Mar 17, 2015

I have a query which working fine:

Code:
strSQL = "Select [nazwa], [id_wycena_pre], [Format_(X)], [Format_(Y)], [kolory p], [kolory t], [nazwa_id], [iloscstron], [numerarkusza], [naklad_pracy], [Kolory P], [Kolory T] from tblGoraZleceniaNowaWyceny where [id_wycena_pre]=" & Forms!frmWycenyObszarRoboczy!ID_wycena_pre & " and [nazwa]='" & "środek" & "' or [nazwa]='" & "okładka" & "'"
Set rst = CurrentDb.OpenRecordset(strSQL)...

But now I would like to add next condition to this query

Code:
where [kolory p] is not null or [kolory t] is not null

- these fields are string

I don't know how to write this condition and add to my exiting strSQL string

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved