troubleshooting Question

Access 97: How to programmatically set a Form's RecordSource to a string longer than 255 characters?

Avatar of SOTA
SOTAFlag for Canada asked on
Microsoft AccessSQL
3 Comments1 Solution56 ViewsLast Modified:
I have Access 97 and need to set a Form's recordset to a string, Problem is my SQL string exceeds 255 characters, and so using
 Dim db As Database
  Dim rs As Recordset
  Set db = DBEngine.Workspaces(0).Databases(0)   ' Create database reference.

  Dim strSQL As String
  strSQL = "SELECT InvoiceOrderEntry.InvoiceID" & vbCrLf
  strSQL = strSQL & "           , InvoiceOrderEntry.InvoiceType" & vbCrLf
  strSQL = strSQL & "           , InvoiceOrderEntry.MainID" & vbCrLf
  strSQL = strSQL & "           , InvoiceOrderEntry.InvoiceNumber" & vbCrLf
  strSQL = strSQL & "           , RepairsRMAInformation.OriginalShippingDate" & vbCrLf
  strSQL = strSQL & "           , InvoiceOrderEntry.ShipDate" & vbCrLf
  strSQL = strSQL & "           , Products.ProductID" & vbCrLf
  strSQL = strSQL & "           , Products.ProductModelNumber" & vbCrLf
  strSQL = strSQL & "           , RepairsRMAInformation.UnitSerialNumber" & vbCrLf
  strSQL = strSQL & "           , RepairsRMAInformation.WarrantyPeriod" & vbCrLf
  strSQL = strSQL & "           , IIf([OriginalShippingDate]+([RepairsRMAInformation].[WarrantyPeriod])<=Date(),""Expired"",IIf(IsNull([OriginalShippingDate]),""Unknown"",""Active"")) AS WarrantyStatus" & vbCrLf
  strSQL = strSQL & "           , IIf([OriginalShippingDate]+([RepairsRMAInformation].[WarrantyPeriod])<=Date(),False,IIf(IsNull([OriginalShippingDate]),False,True)) AS UnderWarrantyYN" & vbCrLf
  strSQL = strSQL & "           , RepairsRMAInformation.Technician" & vbCrLf
  strSQL = strSQL & "           , Sum(InvoiceOrderDetails.OrderAmountMGC) AS SumOfOrderAmountMGC" & vbCrLf
  strSQL = strSQL & "        FROM ((InvoiceOrderEntry " & vbCrLf
  strSQL = strSQL & "  INNER JOIN RepairsRMAInformation
  strSQL = strSQL & "          ON InvoiceOrderEntry.InvoiceID = RepairsRMAInformation.InvoiceID) " & vbCrLf
  strSQL = strSQL & "  INNER JOIN Products " & vbCrLf
  strSQL = strSQL & "          ON InvoiceOrderEntry.ProductModelNumber = Products.ProductModelNumber) " & vbCrLf
  strSQL = strSQL & "  INNER JOIN InvoiceOrderDetails " & vbCrLf
  strSQL = strSQL & "          ON InvoiceOrderEntry.InvoiceID = InvoiceOrderDetails.InvoiceID" & vbCrLf
  strSQL = strSQL & "       WHERE (((InvoiceOrderEntry.Shipped)=True))" & vbCrLf
  strSQL = strSQL & "    GROUP BY InvoiceOrderEntry.InvoiceID" & vbCrLf
  strSQL = strSQL & "           , InvoiceOrderEntry.InvoiceType" & vbCrLf
  strSQL = strSQL & "           , InvoiceOrderEntry.MainID" & vbCrLf
  strSQL = strSQL & "           , InvoiceOrderEntry.InvoiceNumber" & vbCrLf
  strSQL = strSQL & "           , RepairsRMAInformation.OriginalShippingDate" & vbCrLf
  strSQL = strSQL & "           , InvoiceOrderEntry.ShipDate" & vbCrLf
  strSQL = strSQL & "           , Products.ProductID" & vbCrLf
  strSQL = strSQL & "           , Products.ProductModelNumber" & vbCrLf
  strSQL = strSQL & "           , RepairsRMAInformation.UnitSerialNumber" & vbCrLf
  strSQL = strSQL & "           , RepairsRMAInformation.WarrantyPeriod" & vbCrLf
  strSQL = strSQL & "           , IIf([OriginalShippingDate]+([RepairsRMAInformation].[WarrantyPeriod])<=Date(),""Expired"",IIf(IsNull([OriginalShippingDate]),""Unknown"",""Active""))" & vbCrLf
  strSQL = strSQL & "           , IIf([OriginalShippingDate]+([RepairsRMAInformation].[WarrantyPeriod])<=Date(),False,IIf(IsNull([OriginalShippingDate]),False,True))" & vbCrLf
  strSQL = strSQL & "           , RepairsRMAInformation.Technician" & vbCrLf
  strSQL = strSQL & "      HAVING (((InvoiceOrderEntry.InvoiceType)=""CR"") " & vbCrLf
  strSQL = strSQL & "         AND ((InvoiceOrderEntry.ShipDate) Between [Forms]![RepairSummaryReport_preselect]![FromDate] " & vbCrLf
  strSQL = strSQL & "         AND [Forms]![RepairSummaryReport_preselect]![ToDate]) " & vbCrLf
  strSQL = strSQL & "         AND ((Products.ProductID)=[Forms]![RepairSummaryReport_preselect]![ProductModelNumber]))" & vbCrLf
  strSQL = strSQL & "    ORDER BY InvoiceOrderEntry.ShipDate DESC;"

  Set rs = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges, dbOptimistic)

Me.RecordSource = strSQL
results in an error.
How can I set the Form's RecordSource in this case programmatically?
ASKER CERTIFIED SOLUTION
aikimark
Get vaccinated; Social distance; Wear a mask

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2014

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros