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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with inserting Query

Status
Not open for further replies.

Jayzxtx

Technical User
Oct 2, 2007
6
US

Jerry,

Thanks for the Help I am still having problems on where to insert the TOP Value SQL exression. I am trying to get the top 3 in my query to show up in my subform6. I attempted to write another sql command titled strGetSQL. Everytime I try to run this there says there is a syntax error.Any ideas on the possible errors? does my code look alright?

Below is the code listed


Private Sub CalculateZip_Click()
Dim sqlString As String
Dim strGetSQL As String


If Not IsNull(Me.Combo14.Value) Then
sqlString = sqlString & "[Zodiaq Zip Locations_Zip] = " & Combo14.Value & " AND "
End If




If Len(sqlString) > 5 Then
sqlString = Left(sqlString, Len(sqlString) - 5)
Else
End If





Me.SA_Distance_Calc_subform6.Form.FilterOn = True
Me.SA_Distance_Calc_subform6.Form.Filter = sqlString


Me.SA_Distance_Calc_subform6.Form.Requery
Me.Refresh



'MasterForm.DoCmd.OpenQuery SQLCommand


strGetSQL = "SELECT TOP 3 [Service Agent],State,city" _
& "FROM Forms!SA_Distance_Calc_subform6" _
& "WHERE [Zodiaq Zip Locations_Zip] = Forms!SA_Distance_Calc_subform6!Combo14.Value" _
& "ORDER BY [Travel Cost];"


Me.SA_Distance_Calc_subform6.Form.FilterOn = True
Me.SA_Distance_Calc_subform6.Form.Filter = strGetSQL


Me.SA_Distance_Calc_subform6.Form.Requery
Me.Refresh



'MasterForm.DoCmd.OpenQuery SQLCommand
On Error GoTo Err_CalculateZip_Click
' DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70




Exit_CalculateZip_Click:
Exit Sub

Err_CalculateZip_Click:
MsgBox Err.Description
Resume Exit_CalculateZip_Click

End Sub






 
This might not be the whole cause (but will be a problem)but you have no spaces before line continuation characters therefore everything on a seperate line will be a continuation of the last word e.g.
Code:
SELECT TOP 3 [Service Agent],State,cityFROM Forms!SA_Distance_Calc_subform6WHERE [Zodiaq Zip Locations_Zip] = Forms!SA_Distance_Calc_subform6!Combo14.ValueORDER BY [Travel Cost];"
You will need to add a space char on the end before each " _

Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top