Run-time Error (Can't nail it down) (1 Viewer)

Tango

DB/Application Dev Newbie
Local time
Today, 11:07
Joined
Jun 23, 2011
Messages
141
Evening guys,
I have a user getting a runtime error on the below code (near the bottom "RUN LINKDB()" is where the debugger highlights. It works great on my computer but for some reason not on his. I checked all his reference libraries and they match mine. Any thoughts?

The on load code for my main form:
Code:
Private Sub Form_Load()
Dim suser As String
    Dim sSQL As String
    Dim CurUser As String
    
    suser = Environ("username") 'Name of real person
        'MsgBox "sUser = " & sUser
    'MsgBox "curUser = " & CurrentUser()
    Forms![enable macro page]![Text210] = suser
    
    
    'If suser = "clinton.pilgrim" Then
    'MsgBox ("..... ..... ..... ....."), vbOKOnly
    'DoCmd.OpenForm "Misc"
    'Exit Sub
    'End If
'-----------------------------
curtbl = CurrentDb.TableDefs("help table").Connect

  On Error GoTo con_error
  
  Dim cnn As ADODB.Connection
   Set cnn = New ADODB.Connection
   'Set the provider property to the OLE DB Provider for ODBC.
   cnn.Provider = "MSDASQL"
   ' Open a connection using an ODBC DSN.
   cnn.ConnectionString = "driver={SQL Server};" & _
      curtbl
   cnn.Open
   ' Find out if the attempt to connect worked.
   If cnn.State = adStateOpen Then
      
   Else
      MsgBox "Sorry. The server is not responding."
   End If
   ' Close the connection.
   cnn.Close
 
backswap.backgroundswap
    
Dim intStore As Integer
'Count of uncomplete jobs that are past the Expected Completion Date
intStore = DCount("[JobNumber]", "[tblJobs]", "[ExpectedCompletionDate] <=Now() AND [Complete] =0")
'If count of uncomplete jobs is zero display switchboard
'Else display message box detailing amount of jobs
'and give the user the option as to whether to view these or not.
    If intStore = 0 Then
    DoCmd.OpenForm "Start Page", acNormal
    
               Exit Sub
                Else
                    If MsgBox("There are " & intStore & " uncompleted jobs" & _
                    vbCrLf & vbCrLf & "Would you like to see these now?", _
                    vbYesNo, "You Have Uncomplete Jobs...") = vbYes Then
                    DoCmd.Minimize
                    DoCmd.OpenForm "frmReminders", acNormal
                Else
                    DoCmd.OpenForm "Start Page", acNormal
            Exit Sub
        End If
    End If
    
con_Exit:
    Exit Sub
    
con_error:
  Dim resp
  Dim resp2
  resp = MsgBox("Server Connection Failed!" & vbCrLf & vbCrLf & "Would you like to change the name of your base server?", vbYesNo)
If resp = vbYes Then
    On Error Resume Next
        [B]Run linkDB()
[/B]        Else
        resp2 = MsgBox("Server Connection Failed!" & vbCrLf & vbCrLf & "Would you like to retry the connection?", vbYesNo)
            If resp2 = vbNo Then
                Application.Quit
            Else
            DoCmd.Close acForm, "enable macro page"
            DoCmd.OpenForm "enable macro page", acNormal
            End If
            
End If

End Sub

the Run linkDB line calls the below module:
Code:
Option Compare Database
Public Function linkDB()
On Error GoTo err_update
Dim dbs As DAO.Database
  Dim tdf As DAO.TableDef
  Dim Newserver As String
    
Newserver = InputBox("Enter the network name of the server you wish to use:" & vbCrLf & vbCrLf & "Example: SSC-CS-SQL02", _
                           "Bind To New Server")
    
  'If the user clicks cancel or gives a null length responce the server change will abort
  
If Newserver <> "" Then
MsgBox "Server Selected: " & Newserver & vbCrLf & vbCrLf & "Please be patient as the server is located. This process can take up to a minute."
  Set dbs = CurrentDb()
  ' Loop through TableDefs collection, only processing
  ' the table if it already has a Connection property.
  ' (all other tables are local ... not linked)
  For Each tdf In dbs.TableDefs
    If tdf.Connect <> "" Then
      tdf.Connect = "ODBC;DRIVER={SQL Server};SERVER=" & Newserver & ";DATABASE=QP3;Trusted_Connection=Yes"
      tdf.RefreshLink
    End If
  Next
Else
MsgBox "Server change request canceled or invalid response given."
Application.Quit

End If
exit_fun:
Exit Function
err_update:
MsgBox "The update experienced errors and will be canceled. This is likely because the server requested is not available."
Application.Quit
End Function
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:07
Joined
Aug 30, 2003
Messages
36,133
Delete the word "Run" and try it.
 

Tango

DB/Application Dev Newbie
Local time
Today, 11:07
Joined
Jun 23, 2011
Messages
141
It gives an "expected =" syntax error if I remove the word "Run".
 

Tango

DB/Application Dev Newbie
Local time
Today, 11:07
Joined
Jun 23, 2011
Messages
141
Just tried Call and it compiles. now to see if it works.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:07
Joined
Aug 30, 2003
Messages
36,133
Call is optional, I typically don't use it. I would just have:

linkDB
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:07
Joined
Aug 30, 2003
Messages
36,133
To clarify regarding Call, from VBA help:

You are not required to use the Call keyword when calling a procedure. However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the Call keyword, you also must omit the parentheses around argumentlist.
 

Tango

DB/Application Dev Newbie
Local time
Today, 11:07
Joined
Jun 23, 2011
Messages
141
Call is optional, I typically don't use it. I would just have:

linkDB


but when I did that it gave me a syntax error "expected=" and wouldn't compile. I think it was looking at it like I was setting a variables value.
 

pr2-eugin

Super Moderator
Local time
Today, 16:07
Joined
Nov 30, 2011
Messages
8,494
To clarify regarding Call, from VBA help:

You are not required to use the Call keyword when calling a procedure. However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the Call keyword, you also must omit the parentheses around argumentlist.
Paul, please forgive me if I am wrong in this issue.. I agree with you, but that is the case for Procedures (Sub), however the user has declared the LinkDB as a Function, which might expect a return value, though there is no LOC that does that (i.e) something like
Code:
LinkDB = Null
My general assumption in this case was, Functions has to be Called for unlike Sub; just as the Help states..

Since the OP is not returning any values, if he/she changes it to a Sub just using LinkDB will suffice (I think :confused:)
 

Tango

DB/Application Dev Newbie
Local time
Today, 11:07
Joined
Jun 23, 2011
Messages
141
That matches what I am seeing from the compiler. Makes sense too.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:07
Joined
Aug 30, 2003
Messages
36,133
My general assumption in this case was, Functions has to be Called for unlike Sub; just as the Help states..

Since the OP is not returning any values, if he/she changes it to a Sub just using LinkDB will suffice (I think :confused:)

All I can say is that hasn't been my experience. Here's the first line of a function in a production db I happen to have open:

Private Function AddCharge()

and in other places on the form I fire it off with simply:

AddCharge

And another one in a standard module:

Public Function AgingDates(AsOfDate As Date, WhichOne As Integer) As Date

used to build SQL:

& AgingDates(Me.txtFromDate, 1) & "', '" _
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 01:07
Joined
Jan 20, 2009
Messages
12,856
All I can say is that hasn't been my experience. Here's the first line of a function in a production db I happen to have open:

Private Function AddCharge()

and in other places on the form I fire it off with simply:

AddCharge

In this case the function has no arguments. Is is automatically being run as a Sub. If it had a single argument you would see the line rearrange itself with a space between the name and the parameter as it is with a Sub.

Give it two arguments and it will insist on being run as a Function and hence the syntax would require the parameters be enclosed in parentheses.

Note that it you put the single parameter in parentheses, these parentheses are not actually surrounding the parameters as such but indicating the parameter is to be passed ByVal regardless of the argument declaration in the function. The function will still run as a Sub. You can see this because, unlike a function there will be a space between the function name and the opening parenthesis.

When it is forced to run as a function it must either be part of an equation or be Called.

The Call keyword actually forces a function to run as a Sub.

By coincidence I posted some on this at UtterAccess yesterday.
http://www.utteraccess.com/forum/Call-Public-Function-t1998546.html&st=20&start=20

And another one in a standard module:

Public Function AgingDates(AsOfDate As Date, WhichOne As Integer) As Date

used to build SQL:

& AgingDates(Me.txtFromDate, 1) & "', '" _

The function is being used in an equation so that is just fine.
 

Users who are viewing this thread

Top Bottom