Syntax For Empty Query Recordset Test
Sep 6, 2006Can someone tell me the VBA code for testing whether a query recordset is empty or not?
View RepliesCan someone tell me the VBA code for testing whether a query recordset is empty or not?
View RepliesI'm trying to write record set contents to excel. My query runs perfect in access query wizard, but recordset showing as null. My VBA code
Code:
Dim cnn As ADODB.Connection
Dim recordst As ADODB.Recordset
Dim strSQL As String
Dim strPath As String
Dim appXL As Excel.Application
Dim wb As Excel.Workbook
[Code] ....
Help.
I can seem to find a way to test if the SQL for my record set returns value. I've tried using the if statement with .BOF and .EOF. When there are no records returned for the criteria, there should be a way to test it with IF. I can't seem to figure it out. Using the record count does not work because it also returns at least one record. Help.
Here is the code
Dim rsContacts As ADODB.Recordset
Set rsContacts = New ADODB.Recordset
SQLStr = "SELECT FormatPercent(((43200-Sum(DateDiff('n',[tblOutageDetail.StartTime],[tblOutageDetail.endtime])))/43200),2) AS ElapsedTime FROM (qryOutageTotalMin INNER JOIN tblOutageData ON qryOutageTotalMin.Outage = tblOutageData.Outage) INNER JOIN tblOutageDetail ON tblOutageData.Outage = tblOutageDetail.Outage WHERE (((tblOutageData.System)='PARK PRIMARY') AND ((tblOutageDetail.StartTime)>=Date()-30) AND ((tblOutageDetail.OtgCat)=1))"
With rsContacts
.Open SQLStr, CurrentProject.Connection, adOpenStatic, adLockReadOnly
End With
'Me!btnparkpri.Caption = CStr(rsContacts!ElapsedTime)
'Set rsContacts = Nothing
If rsContacts.RecordCount = 1 Then
Me!btnparkpri.Caption = CStr(rsContacts!ElapsedTime)
End If
If Me!btnparkpri.BackColor = 255 Or Me!btnparkpri.BackColor = 32768 Then
Me!btnparkpri.ForeColor = 16777215
End If
Set rsContacts = Nothing
I have the following VBA code to select certain records from table to recordset, however, sometimes no records existed and movefirst should give error message. Just want to know how to know there got no records in the TRANS2 in case no criteria is matched??
Set TRANS2 = db.OpenRecordset("SELECT * FROM TRANSACTION WHERE tcode = 't12345'", dbOpenDynaset)
TRANS2.MoveFirst
Hi,
I'm trying to set a variable equal to a subform's recordsetclone, for the purpose of looping through the subform's recordset. The problem seems to be in referencing the subform's recordsetclone.
Here's the giant set of commands that are causing the problem:
Dim rst As ADODB.Recordset
Set rst = Forms!frmMailingLists!qfrmMLMembers.Form.Recordset Clone
Whether I use Recordset or RecordsetClone, I get the same error:
Run-time 2455: You entered an expression that has an invalid reference to the property Form/Report.
I've tried many other variations as well, which cause other errors, so I'm starting with this.
I don't think that any of the other code in the Sub is related to the problem, in part because I get the same error when I run this in the immediate window.
A solution would be greatly appreciated!
Thanks,
David
/dmrst
Can anyone tell me how to delete a recordset if a control is empty?
I have my form set up to automatically display the users ID which is bound to a table. If the user exits the form without entering any data I end up with a recordset that only has the users ID in it and nothing else. What I would like to do is set up an on close event in VBA that will check if other data exists in the table, otherwise delete that recordset. I'm not very familiar with this recordset.delete thing. Can anyone clarify?
Are new, empty record in form have recordset presentation, how to get recordset in form for empty row?
View 1 Replies View Relatedmy issue is i have multilble text box in my form & based on change in one of this text box i need the code to compare between data in the form & table & returm Msg if it is not matching. attached screen FYI.
i look in the internet but i could not figuer out the VBA code since i do not know VBA. what comes to my mind to to use select case.
I'm using Access 2003...I have a query that searches a parts table by description:
Like "*" & [Enter in Part Description to search] & "*"
I need to add another search to this query, I added another field to the parts table call manufacturer. I add this field to the above query and added this parameter to it:
Like [Enter in Manufacturer] & "*"
I then added a manufacturer to one of the fields for test purposes. For some odd reason this doesn't work. If I take out the manufacturer parameter and don't enter in anything into the part description the query returns all the records. When i type a description into the part description field the query returns the proper records. When I add back the manufacturer parameter and enter through both parameters only the one record returns showing the test record instead of all of them. If I put a part description in and enter through the manufacturer parameter no records show when they should.
I've tried adding a test field to a different table and tried a different query using the like parameter. The parameter works in a field already in the table but won't work with the new field I added. I've done compact and repair.
Hello,
I have just created a query so that I may base my report on it. The query ties together 4 tables. I only included the fields that will be in my report. I created the report using the wizard and used my new query as the source but it does not want to work. I tried opening the query and it was empty even though I have entries in the database.
ANY IDEAS :confused:
Hello, I have writen a piece of code:
Code:DoCmd.RunSQL "SELECT tblTrades.tradeID, tblTrades.TradeConfirm, tblTrades.Laurent FROM tblTrades WHERE (((tblTrades.TradeConfirm)=No) AND ((tblTrades.Laurent)=Yes));"
How do I check to see if it returns any results?
i have a form which has as button that opens a query
how can i make it so that if there arent any results from the query then a error message will pop up saying "no results found" and the table dosent show?
I have a text file that I will be importing into a new table once a week (every week) that I will need to add about 30 more columns to before I export it to a new text file in preparation for importing it into another Access application.
Is there a way through a query to add the columns without having to open the table and manually add them each week?
Thanks,
David
Hi...I have the following requirement:
I have a table called "tblselectrso" with the following fields:
stockno rso1 rso2 rso3 rso4 rso5
s1 1 3
s2 2 4 5
stockno is a text field and rso1 through rso5 is a Number field.
Given the value of "stockno" I want to run a query to list all the other fields (rso1 through rso5) that are NON-EMPTY.
Is this possible at all? Can anyone help me please?
Thanks
Please find attached a sample db.
I have a Query pulling data from several tables. If there are empty cell with no data in them, they cause the Query to completely skip that record. It does not show up in the Query. Not practical since most of the data int the table will not be entered until some time later.
What gives? Is there a way around this?
Thanks.
Query not responding: empty fields?
I have a table with a field 'Fax number', type: text (since occasionally we write a comment in there, like 'prohibited').
Some records have fax numbers, others are empty.
I want to find all records which do have a fax number. So I wrote into the Query: "is not null", expecting to get only the records which have a fax number or some text in them.
In fact, all records came up in the query, empty as well as non-empty fax fields.
I was wondering if the 'empty field' had a blank space in them, but could not find any. Tried backspace key, but there was nothing to backspace on.
I used the find-replace utility and searched for single space in Whole Field. It picked out quite a few records, but not all - so something invisible seems to be there.
However, when I opened the 'replace' window of find/replace, and had the replace window empty, then clicked 'replace', the msg came 'Access cannot find the specified text'.
What am I doing wrong? What do I have to do to get the query to work?
Thanks,
Adrian
Hi All
I have a feeling that this is an absolute newbie question.
I have three queries, qryVisitsDue, qryVisitsOverDue, qrySiteView.
The query qrySiteView uses SiteID to produce a listing of all sites which includes a count of visits for those sites. If there is no visit data the site does not display. To display the counts I'm using the other two queries. In the first two I'm querying a table, tblVisits, to find what visits are due or overdue based on the current date. They work fine where there is visit data. My problems start when there is no data for a site. I need to be able to show the sites where there is no visit data.
I'm not very experienced so basic explanations are probably the best.
Any help much appreciated.
ChrisD
I have a dataset showing sales by salesperson for each product. I'd like to summarize this data in a table that looks like this:
Note that some salespeople don't sell certain products and that these records show up with "0". My problem is that, in my actual dataset, if a salesperson doesn't sell a product, that records doesn't exist at all. Is there any way to append empty "0" records to my dataset? See attached for an Access file.
DatasetProblem.accdb
I am really stuck. I have spent two days searcinh different forums trying to solve my problem. I am trying to create an UPDATE q to my Access database. But I get either the: "Syntax error in query. Incomplete query clause" or "Syntax error in UPDATE query".
First of all here's the URL: www.innotec-as.no/login/Kunder
Login U/P either: "alfen" or "thomas".
The page opening up shows the user info, U/P and adress.
viewing the information is working perfectly - but editing it..no way.
When editing and submiting the data the above errors occour.
Try that and you'll also see the SQL I am trying to execute.
The CODE is as follows:
SQLtemp = "UPDATE 'Brukere' SET"
SQLtemp = SQLtemp & " 'navn' = '" & request("Navn") & "', "
SQLtemp = SQLtemp & " 'epst' = '" & request("Epst") & "', "
SQLtemp = SQLtemp & " 'Pass' = '" & request("Pass") & "', "
SQLtemp = SQLtemp & " 'Firma' = '" & request("Firma") & "', "
SQLtemp = SQLtemp & " 'BAdresse' = '" & request("BAdresse") & "', "
SQLtemp = SQLtemp & " 'BPostAdr' = '" & request("BPostAdr") & "', "
SQLtemp = SQLtemp & " 'PAdresse' = '" & request("PAdresse") & "', "
SQLtemp = SQLtemp & " 'PPostAdr' = '" & request("PPostAdr") & "', "
SQLtemp = SQLtemp & "WHERE 'Bnavn' = '" & request("Bnavn") & "'"
Response.Write(SQLtemp)
Response.End()
conn.Execute(SQLtemp)
rs.Update[/COLOR]
The finished SQL statement looks like this:
UPDATE 'Brukere' SET 'navn' = 'Alf Byman', 'epst' = 'alf@baccara.no', 'Pass' = 'alfen', 'Firma' = '', 'BAdresse' = '', 'BPostAdr' = '', 'PAdresse' = 'sdfg', 'PPostAdr' = '', WHERE 'Bnavn' = 'alfen'
I have tried to user single quotes, doubble quotes, brackets etc. nothing works.
The code I use for connection is as follows:
<!--#include file="../adovbs.inc"-->
<%
dim conn, rs, SQLtemp
' DSNless connection to Access Database
set conn = server.CreateObject ("ADODB.Connection")
rs="DRIVER={Microsoft Access Driver (*.mdb)}; "
rs=rs & "PWD=uralfjellet; DBQ=" & server.mappath("../../../../db/kunder.mdb")
conn.Open rs
I'll be very HAPPY for some expert help on this.
I keep on getting a syntax error on the first [MU_ID]. Can anyone tell me what am I doing wrong please? You can e-mail me at Frank.Cappas@CIGNA.Com
Site: IF [MU_ID] BETWEEN ((SELECT [MU_Start] FROM [Sites] WHERE [Site] = “BRB”) AND (SELECT [MU_End] FROM [Sites] WHERE [Site] = “BRB”), “BRB”, {IF [MU_ID] BETWEEN ((SELECT [MU_Start] FROM [Sites] WHERE [Site] = “BRI”) AND (SELECT [MU_End] FROM [Sites] WHERE [Site] = “BRI”},"BRI")
Thank you so much in advance,
Frank
I'm trying to get my head round this query and not having much luck.
I have table that contains. amongst others, two fields I need to use - Date and Amount. I already have a query that returns me the number of entries for a given month, along with the total value.
SELECT Count(*) AS [Number of Entries],
Sum(NBReferral.[Amount]) AS [Total Amount],
NBReferral.Date
FROM NBReferral
GROUP BY NBReferral.Date;
What I want is to also provide a running total (year to date). Using this:
SELECT Count(*) AS [YTD Number of Entries],
Sum(NBReferral.[Amtount]) AS [YTD Total Amount]
FROM NBReferral;
Combing the two queries works as long as there is only one month. Unfortunately, I'd like to see each month's YTD figure displayed as shown
Date Number of Entries Total Amount YTD Number of Entries YTD Total Amount
Nov 2006 5 10000 5 10000
Dec 2006 3 5000 8 15000
Jan 2007 6 12000 14 27000
etc.
What I currently get, as you would expect, are the same YTD totals applied to each month:
Date Number of Entries Total Amount YTD Number of Entries YTD Total Amount
Nov 2006 5 10000 14 27000
Dec 2006 3 5000 14 27000
Jan 2007 6 12000 14 27000
etc.
Probably a fairly straight-forward query for someone with a bit more experience. Any ideas?
Hi all,
I have the following code that works really well for me:
Me.lstEngines.RowSource = "Select [Engine Name], [Type], [Engine #] " & _
"From [Main Data Entry] " & _
"Where [Engine Name] like '*" & Me.txtsearch & "*'"
Me.lstEngines.Requery
I need to make one modification to it, but I am getting lost in the syntax.
Right now this code is matching the text string "txtsearch" to anything in the "Engine Name" Field.
It works fine, but I need it to also look in the "type" field. I need results if the string is in "Engine Name" OR if it is in "Type"
How do I do that?
Thanks
I want to run a query that allows the user to enter the beginning date and the ending date to produce the results for all items within those dates. I've written this before using "Between", but I can't get the syntax correct.
HEEELLLLLLPPPPPPPPPP
thanks
Special situation: The SQL Server Linked Server across the country is linked to a Read Only Oracle DB. This data pull works perfectly and populates the Subform.
The problem is that Oracle can take 3 to 6 seconds to retrieve the single record depending on the network traffic through a small pipe.
The code below shows the RecordSource for the SubForm. clicking on a list box supplies the value. Then 3 to 6 seconds later, the subform populates.
The actual Recordset for this Recordsource is needed to conduct Validation on each field. Normally this would be on SQL Server, I might just create a Recordset Oject and run this SQL statement again in 1 milisecond. In this case, it will probably take an additional 3 to 6 seconds. Avoiding another lengthy round-trip to Oracle would be prefered.
Goal: How does one grab, clone, or other wise reference the existing recordset for the SubForm?
Note: Immediate Window - One single field can be returned quickly
There are 48 fields that need validation - is there a way to reference the entire recordset?
Immediate Window during Break Mode:
? me.fsubsrNavSHLBHL("NavSH_QQ")
NESE ' this is the correct value for the current recordsource
Set a breakpoint right after the line:
fsubsrNavSHLBHL.Form.RecordSource = "Select * from vsrNavigatorSHLBHL where Well_ID =" & txtNavWellID.Value
Immediate Window:
? me.fsubsrNavSHLBHL.Form.RecordSource
Select * from vsrNavigatorSHLBHL where Well_ID =91229
I'm trying to create a query which will only show fields that have information in them, but I can't figure out how to do it.
View 2 Replies View RelatedI have a main form with two unbound text boxes that filter a subform with a select query in the record source. The problem is that it only works sometimes.when I copy and paste the SQL into a query instead of the form it works all the time. for example when I open the query and the form side by side with the same SQL the form does not show results but the Query does, and yes I have "requeried" both of them after entering criteria into the unbound text boxes.
Here is the SQL:
SELECT [Quote_ID] & "-" & [Version] AS QuoteIDv, tblQuoteID.Quote_Type,
tblQuoteID.Quoted_By, tblQuoteID.Agency, DLookUp("[Contact]",
"tblContacts","[QuoteID] = '" & [Quote_ID] & "' And [Version] = '" & [Version] & "'") AS contact,
tblQuoteID.Quote_Date, tblQuoteID.FileName, tblQuoteID.FileLocation, tblQuoteID.Amount,
tblQuoteID.Active, tblQuoteID.Quote_ID, tblQuoteID.Version, tblQuoteID.Selected
[Code] .....