Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with ADODB Recordsets

Status
Not open for further replies.

Nick34

Technical User
Oct 16, 2003
50
US
I am trying to create a search on a recordset that is based on a SQL string. If the search comes back with nothing, then I want to exit the sub routine. What am I doing wrong???

strSQL = "SELECT NGSCommunityCommitmentTons.ID, NGSCommunityCommitmentTons.Unit, NGSCommunityCommitmentTons.Month_Year, NGSCommunityCommitmentTons.SO2Tons, NGSCommunityCommitmentTons.NOxTons, NGSCommunityCommitmentTons.PMTons, NGSCommunityCommitmentTons.COTons, NGSCommunityCommitmentTons.VOCTons " & _
"FROM NGSCommunityCommitmentTons " & _
"WHERE (((NGSCommunityCommitmentTons.Unit)= " & sUnit & ") AND ((NGSCommunityCommitmentTons.Month_Year)= 10/1/2003 ));"

Set rst = New ADODB.Recordset
Set rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.Source = strSQL
rst.Open Options:=adCmdText


If rst.EOF Then
Exit Sub
Else: msgbox "There is already data entered for this month. Use the " & _
"NGS Community Commitment Update Form.", vbOKOnly
End If
 
Dates is Access need to be surrounded by literal identifier the #.

"((NGSCommunityCommitmentTons.Month_Year)= #" & 10/1/2003 & "#));"

rst.Open strSQL
 
I'm still getting the error message "No value given for one or more required parameters."

Any ideas?
 
After this.
strSQL = "SELECT NGSCommunityCommitmentTons.ID, NGSCommunityCommitmentTons.Unit, NGSCommunityCommitmentTons.Month_Year, NGSCommunityCommitmentTons.SO2Tons, NGSCommunityCommitmentTons.NOxTons, NGSCommunityCommitmentTons.PMTons, NGSCommunityCommitmentTons.COTons, NGSCommunityCommitmentTons.VOCTons " & _
"FROM NGSCommunityCommitmentTons " & _
"WHERE (((NGSCommunityCommitmentTons.Unit)= " & sUnit & ") AND ((NGSCommunityCommitmentTons.Month_Year)= 10/1/2003 ));"

DO This.
Debug.Print strSQL
and paste in your resulting SQL Statement.
 
SELECT NGSCommunityCommitmentTons.ID, NGSCommunityCommitmentTons.Unit, NGSCommunityCommitmentTons.Month_Year, NGSCommunityCommitmentTons.SO2Tons, NGSCommunityCommitmentTons.NOxTons, NGSCommunityCommitmentTons.PMTons, NGSCommunityCommitmentTons.COTons, NGSCommunityCommitmentTons.VOCTons FROM NGSCommunityCommitmentTons WHERE (((NGSCommunityCommitmentTons.Unit)= NS1) AND ((NGSCommunityCommitmentTons.Month_Year)= #10/1/2003# ));

This is what I got after I debug.print the SQL statement.

I'm still getting the same error as before.
 
I think your problem lies here
Code:
NGSCommunityCommitmentTons.Unit)= NS1
as NS1 is a string and as such, should be surrouded by single quotes. You might try the following change to the SQL statement
Code:
WHERE (((NGSCommunityCommitmentTons.Unit)=
Code:
'
Code:
" & sUnit & "
Code:
'
Code:
) AND

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I thought tons was numeric, but I can see it is not. You will need to work it out with quotes.

WHERE (((NGSCommunityCommitmentTons.Unit)= "NS1") AND
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top