Corrupt DB - VB code problem?

B

BarbaraC

I have an application used to enter data for medical
reports. I am using some code which I found on someone's
web site (can't remember the source) to open the Windows
common dialog box for the user to select a file (which
happens to be a photo). I originally wrote the code
using Windows 98 operating system and I was recently
given a new laptop at work which has XP professional on
it.

I am now having big problems with a corrupted database
and it seems to occur after I use the code to select the
photo file. I've listed the code below. Is the problem
likely to be due the the different operating system? If
so what do I need to change to make it work for Win XP
Professional. Also, my users are using Win 2000 and it
works fine on their systems. How can I detect which
operating system is in use and have the program use the
correct code (if that is the problem)? I am VERY
unfamiliar with low level Windows stuff so any help would
be appreciated!


Option Compare Database
Option Explicit

Private Declare Function GetOpenFileName
Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Function Browse(strform As Form, InitialDirectory As
String) As String 'Select file via common dialog
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = strform.hWnd
sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0)
& _
"JPEG Files (*.JPG)" & Chr(0) & "*.JPG" & Chr(0) & _
"TIF Files (*.TIF)" & Chr(0) & "*.TIF" & Chr(0) & _
"Excel Files (*.XLS)" & Chr(0) & "*.XLS" & Chr(0) &
_
"CSV Files (*.CSV)" & Chr(0) & "*.CSV" & Chr(0)
'sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr
(0) & _
"Bitmap Files (*.BMP)" & Chr(0) & "*.BMP" & Chr(0)
& _
OpenFile.lpstrFilter = sFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
If Not IsNull(InitialDirectory) Then
OpenFile.lpstrInitialDir = InitialDirectory
Else
OpenFile.lpstrInitialDir = "C:\"
End If
'OpenFile.lpstrInitialDir = "C:\"
OpenFile.lpstrTitle = "Select a File"
OpenFile.Flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
Browse = ""
'MsgBox "A file was not selected!",
vbInformation, _
' "Select a file using the Common Dialog DLL"
Else
Browse = Trim(OpenFile.lpstrFile)
If InStr(Browse, Chr$(0)) <> 0 Then Browse =
Left$(Browse, InStr(Browse, Chr$(0)) - 1)

End If
End Function
 
G

Guest

I'm using Access 2000. Should the code you referred me
to work in that version of Access.
 
T

TC

Why do you say that the database is being corrupted? (Ie., what is the
message or other symptoms you are getting?)

TC
 

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

Similar Threads


Top