Runtime error 2580 - Record Source does not exist... (1 Viewer)

mdnuts

Registered User.
Local time
Today, 08:11
Joined
May 28, 2014
Messages
128
I currently have this set as the forms default recordsource (which works just fine):

Code:
SELECT TOP 5 tblUsers_Phone_Book.EMAIL_ADDRESS, weightedDL('me@mine.com',[EMAIL_ADDRESS]) AS Expr1
and i have this vba to dynamically switch around that email address.

Code:
Private Sub Form_Load()
  Dim intPos As Integer
  Dim strControlName As String
  Dim strValue As String
  Dim sSQL As String

  If Len(Me.OpenArgs) > 0 Then
    ' Position of the pipe
    intPos = InStr(Me.OpenArgs, "|")
    If intPos > 0 Then
      ' Retrieve Control Name from the first part of the string
      strControlName = Left$(Me.OpenArgs, intPos - 1)
      ' Retrieve Value to Assign from the end of the string
      strValue = Mid$(Me.OpenArgs, intPos + 1)
      ' Assign the value to the control
    End If
  End If

  sSQL = "SELECT TOP 5 tblPriv_Users_Phone_Book.EMAIL_ADDRESS, weightedDL('" & strValue & "',[EMAIL_ADDRESS]) AS Expr1"
  With Me.Form
        .RecordSource = sSQL
        .Refresh
  End With

End Sub
If I msgbox the sSQL - it shows identical to the default recordsource but I get the error:

The error message I get is:
Run-Time error '2580'
The record source 'SELECT TOP 5 tblUsers_Phone_Book.EMAIL_ADDRESS, weightedDL('me@mine.com',[EMAIL_ADDRESS]) AS Expr1' specified on this form or report does not exist.
Any ideas? I've banged around it for a bit now and just can't see it. I tried coping the exact working default sql into the vba and get the same result.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:11
Joined
Aug 30, 2003
Messages
36,125
Have you tried adding a FROM clause? I'm amazed it works without at any time.
 

mdnuts

Registered User.
Local time
Today, 08:11
Joined
May 28, 2014
Messages
128
ahh wow, yeah that was it. went the lazy route by creating it in query design to get it functioning properly and somehow it still took it.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:11
Joined
Aug 30, 2003
Messages
36,125
Happy to help. I'm surprised the design window left it out of SQL view. However, I get surprised a lot. :p
 

Users who are viewing this thread

Top Bottom