PC Review


Reply
Thread Tools Rate Thread

ADO and SQL Statement

 
 
Chris via AccessMonster.com
Guest
Posts: n/a
 
      15th Jun 2005
Hello all,

I have been using ADO to perform some basic data manipulation in single
tables (Looking for a particular field match and modify another fields value).
I have now moved on to one where I am going to have to match two criteria and
I know that with ADO you can not reference a table in your
rsSomeActiveConnection.Open "tblnamehere",,adOpenKeyset,adLockOptimistic,
AdCmdTable statement, so I will have to use an SQL statement.

I created the SQL statement and then checked it based upon one if I created a
query and everything matches.
I then created a form that will ask for the two criteria, Date and Crew
Number. On this same form I have a button that will run the ADO statement,
fill six(6) variables, open a second form and fill the text boxes on the
second form with the six variable.

Just to make sure I am doing this correctly, after I filled one of the
variable, I have it create a message box and display the variable. When I do
this, instead of it coming up with the correct integer, 17 the value it sends
to the message box is 0. Below you will find my VB, and any help on
something I did wrong or if there is an easier way to do this, please let me
know. If you guys know of a site where I could read up on this that would
also be great to know as well. I appreciate all the help and thank you in
advance!
Thanks, Chris

Here is my VB Form:

Dim rsMyConnection As ADODB.Connection
Dim rsMyLocation As New ADODB.Recordset
Dim mySql As String
Dim SurveyFieldCrewNo As Integer
Dim txtFieldDate As Date
Dim SurveyFieldRequestID01 As Integer

mySql = "SELECT tblSurveyFieldScheduler.*, tblSurveyFieldScheduler.
SurveyFieldCrewNo, tblSurveyFieldScheduler.txtFieldDate " & _
"FROM tblSurveyFieldScheduler " & _
"WHERE tblSurveyFieldScheduler.SurveyFieldCrewNo=" & Me.SurveyFieldCrewNo & "
AND tblSurveyFieldScheduler.txtFieldDate= " & Me.txtFieldDate

Set rsMyConnection = CurrentProject.Connection
rsMyLocation.ActiveConnection = rsMyConnection
rsMyLocation.Open mySql, , adOpenStatic

SurveyFieldRequestID01 = rsMyLocation.Fields(2)

rsMyLocation.Close

MsgBox SurveyFieldRequestID01

End Sub

--
Message posted via http://www.accessmonster.com
 
Reply With Quote
 
 
 
 
laudus
Guest
Posts: n/a
 
      15th Jun 2005
If the value of Me.txtFieldDate is a date (which I expect it is) yo
need to modify your code to say

AND tblSurveyFieldScheduler.txtFieldDate = #" & Me.txtFieldDat
& "#

Any time you are comparing date values you have to enclose the valu
you're comparing to in #'s. Hope this helps

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      15th Jun 2005
Just in case the user's Regional Settings don't have the short date format
set to mm/dd/yyyy, it would be better to use

AND tblSurveyFieldScheduler.txtFieldDate = & Format(Me.txtFieldDate,
"\#mm\/dd\/yyyy\#")

Access will not interpret dd/mm/yyyy dates correctly for the first 12 days
of every month.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"laudus" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> If the value of Me.txtFieldDate is a date (which I expect it is) you
> need to modify your code to say :
>
> AND tblSurveyFieldScheduler.txtFieldDate = #" & Me.txtFieldDate
> & "#"
>
> Any time you are comparing date values you have to enclose the value
> you're comparing to in #'s. Hope this helps.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reconcile Bank statement & Credit card statement & accounting data Bklynhyc Microsoft Excel Worksheet Functions 0 7th Oct 2009 09:07 PM
select statement into if statement in an event code (syntax error =?Utf-8?B?dG90YQ==?= Microsoft Access VBA Modules 1 12th Dec 2004 11:13 AM
Dlookup function in a SQL Statement giving Error Expected: End of Statement Edward S Microsoft Access 1 19th May 2004 02:41 AM
Dlookup function in a SQL Statement giving Error Expected: End of Statement Edward S Microsoft Access 1 17th May 2004 08:34 PM
How to chart a profit & loss statement/Profitability analysis statement in Excel Charts Belinda Microsoft Excel Charting 3 3rd May 2004 09:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:39 AM.