Code creating problems in runtime

A

Alp

Hi Experts,

I am facing problems with the following under an MS Access Runtime
environment. Is this a "typical" runtime restriction or am I missing
something?

RT is Access2000, OS is NT. The app runs ssemingly without any problem but
if any form is opened almost instantly an error is generated and the
application closes. The interesting aspect is, there is nothing new under
these forms. Only some code changes under the startup form which does open,
display proper data and behaves normally.

Another point is; when the FE is run from another PC on the network, neither
the startup nor the main menu is displayed. Still all relevant froms are
accessible and functional via the custom menubar. This is temporarily
resolved by commenting the following codes that were called behind the
startup:
Public Function ShowHowManyUsers()
Dim cn As Variant 'New ADODB.Connection
Dim rs As Variant 'As New ADODB.Recordset
Dim i, j As Long

Set cn = CreateObject("ADODB.Connection")

cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.Open "Data Source=" & CurrentDb.Name

Set rs = cn.OpenSchema(-1, , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")

i = 0
While Not rs.EOF
'Debug.Print rs.Fields(0), rs.Fields(1), rs.Fields(2), rs.Fields(3)
i = i + 1
rs.MoveNext
Wend
ShowHowManyUsers = i - 1
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Function

and this one:
Public Function SDBase()
Dim fs, d
If VBA.Left(lokasyon, 2) = "\\" Then
dPth = VBA.Left(lokasyon, (InStr(3, lokasyon, "\", vbTextCompare)))
Else
dPth = VBA.Left(lokasyon, InStr(1, lokasyon, "\", vbTextCompare))
End If
Set fs = CreateObject("Scripting.FileSystemObject")
Set d = fs.GetDrive(fs.GetDriveName(fs.GetAbsolutePathName(dPth)))
SDBase = d.SerialNumber
Set d = Nothing
Set fs = Nothing
End Function

As a reference the code of "lokasyon" is:
Public Function lokasyon()
vtnm = CurrentDb.Name
lokasyon = Left(vtnm, LastInStr(vtnm, "\"))
End Function

Clear as mud?

Thanks in advance.

Alp
 
G

Graeme Richardson

HI Alp, start by entering some error checking code to each Sub:
(e.g.)
Public Function ShowHowManyUsers()
On Error Goto Err_Handler

' Your code here

Exit_Handler:
Exit Sub
Err_Handler:
' Change sub name in msgbox header for each sub.
MsgBox Err.Number & ": " & Err.Description,vbOKOnly, "ShowHowManyUsers"
Resume Exit_Handler
End Sub

With the error checking, you will see the sub name as the title msgbox when
error raised.

Also, declare these variables (in ShowHowManyUsers) explicitly and compile
(why did you change them to Variant data type?)
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Also, and this will take some work, turn on Option Explicit so that you have
to declare your variables, and compile your code.

Also,
Dim i, j As Long
leaves i declared as variant data type. You probably mean
Dim i As Long, j As Long

HTH, Graeme.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top