-
August 8th, 2003, 05:47 AM
#1
Problems while Loading a file.
I am having a weird problem in my application. the problem occurs when I am opening an existing database file on my application. If I press Cancel on the Open Exisiting file dialog box, the application defaultly opens the last database it opened instead of just doing nothing. If you do selected ok to open a database, the application goes through and opens it..which is fine..How do I fix this problem. Here is the relevant code for File Load
Private Sub FileLoad_Click()
CD.Flags = cdlOFNFileMustExist
On Error GoTo fokop
CellText.Visible = False
CD.DialogTitle = "Load existing analysis..."
CD.Filter = "MS Access Database Files (*.mdb)|*.mdb|All Files (*.*)|*.*"
CD.ShowOpen
GlobalDatabaseName = CD.FileName
If GlobalDatabaseName = "" Then
Exit Sub
End If
Dim MyDB As Database, thesql As String, theset As Recordset
Set MyDB = OpenDatabase(GlobalDatabaseName)
thesql = "SELECT * FROM HeaderData"
Set theset = MyDB.OpenRecordset(thesql)
If theset.EOF = False Then
theset.MoveFirst
Text21.Text = Replace(FixNull(theset.Fields(0).Value), "@@@", "")
Text22.Text = Replace(FixNull(theset.Fields(1).Value), "@@@", "")
Text23.Text = Replace(FixNull(theset.Fields(2).Value), "@@@", "")
DTPicker1.Value = FixNull(theset.Fields(3).Value)
DTPicker1.Value = FixNull(theset.Fields(4).Value)
Text24.Text = Replace(FixNull(theset.Fields(5).Value), "@@@", "")
Text25.Text = Replace(FixNull(theset.Fields(6).Value), "@@@", "")
Text26.Text = Replace(FixNull(theset.Fields(7).Value), "@@@", "")
Text1.Text = Replace(FixNull(theset.Fields(8).Value), "@@@", "")
End If
theset.Close
thesql = "SELECT AssemblyName FROM SparesData GROUP BY [AssemblyName]"
Set theset = MyDB.OpenRecordset(thesql)
If theset.EOF = False Then
Combo1.Clear
theset.MoveFirst
Do While theset.EOF = False
Combo1.AddItem theset.Fields(0).Value
theset.MoveNext
Loop
Combo1.Text = Combo1.List(0)
End If
theset.Close
thesql = "SELECT * FROM AnalysisTeam"
Set theset = MyDB.OpenRecordset(thesql)
If theset.EOF = False Then
theset.MoveFirst
k = 0
Do While theset.EOF = False
k = k + 1
FGATeam.TextMatrix(k, 0) = Replace(theset.Fields(0).Value, "@@@", "")
FGATeam.TextMatrix(k, 1) = Replace(theset.Fields(1).Value, "@@@", "")
FGATeam.TextMatrix(k, 2) = Replace(theset.Fields(2).Value, "@@@", "")
theset.MoveNext
Loop
End If
theset.Close
Frame2.Visible = True
SparesMain.Caption = "Spares Definition (" & GlobalDatabaseName & ")"
Call LoadTreeFromAccess
Call FixTreeText
StatusBar1.Panels(2).Text = "File loaded successfully."
Exit Sub
fokop:
StatusBar1.Panels(2).Text = "Unable to perform operation."
Call FileExport_Click
End Sub
-
August 8th, 2003, 05:53 AM
#2
Common Dialog has a property CancelError for cancel button pressing.
You should check for that property true or false.
write the following after cdl.showopen
If cdl.CancelError = false Then
'Write corresponding code here
Exit sub
end if
Last edited by cutamacious; August 8th, 2003 at 05:59 AM.
Cute Member
-
August 8th, 2003, 05:56 AM
#3
Thanks but its not working..what do u mean by write corresponding code here??
-
August 8th, 2003, 06:00 AM
#4
On pressing Cancel on the Load File..it opens the last database it opened.... i dont seem to understand why this is happening..thanks for ur help also
-
August 8th, 2003, 06:03 AM
#5
Originally posted by cutamacious
Common Dialog has a property CancelError for cancel button pressing.
You should check for that property true or false.
write the following after cdl.showopen
If cdl.CancelError = false Then
'Write corresponding code here
Exit sub
end if
Write Corresponding code here refers to any cleanup code u wish to put there like for ex., displaying a msgbox or on status bar etc.,
Cute Member
-
August 8th, 2003, 06:05 AM
#6
Originally posted by azwildcat4ever
On pressing Cancel on the Load File..it opens the last database it opened.... i dont seem to understand why this is happening..thanks for ur help also
well commondialog happens to remember the previous file name it opened. So use the cancelerror property to stop the code following the cdl.showopen statement
Cute Member
-
August 8th, 2003, 06:07 AM
#7
I tried this it worked and did nothing when I click Cancel however now it doesnt do anything when trying to open a database.
-
August 8th, 2003, 06:18 AM
#8
Hope this helps!
Code:
Private Sub Form_Load()
On Error Resume Next
CD.CancelError = True
CD.ShowOpen
If Err.Number = 32755 Then
MsgBox "Cancel was selected"
Else
MsgBox CD.FileName
End If
End Sub
-
August 8th, 2003, 06:27 AM
#9
WEll I just entered CD.CancelError = True after CD.Showopen and it worked fine..weird ???
-
August 8th, 2003, 06:37 AM
#10
Oh!
I think it should only work before ShowOpen.
-
August 8th, 2003, 06:48 AM
#11
Originally posted by azwildcat4ever
WEll I just entered CD.CancelError = True after CD.Showopen and it worked fine..weird ???
Well, you force the commodialog to raise an error by giveing that statement
Cute Member
-
August 8th, 2003, 07:19 AM
#12
so what sohuld i do..where does wht code?c
-
August 8th, 2003, 07:30 AM
#13
Well, just change this part of the code so that it will work..
Code:
CD.Flags = cdlOFNFileMustExist
On Error GoTo fokop
CellText.Visible = False
CD.DialogTitle = "Load existing analysis..."
CD.Filter = "MS Access Database Files (*.mdb)|*.mdb|All Files (*.*)|*.*"
CD.CancelError = True
CD.ShowOpen
Busy
-
August 8th, 2003, 07:33 AM
#14
-
August 8th, 2003, 07:36 AM
#15
Code:
Private Sub FileLoad_Click()
on error resume next
CD.Flags = cdlOFNFileMustExist
CellText.Visible = False
CD.DialogTitle = "Load existing analysis..."
CD.Filter = "MS Access Database Files (*.mdb)|*.mdb|All Files (*.*)|*.*"
CD.CancelError = true
CD.ShowOpen
If Err.Number = 32755 Then
goto Canceled
End If
On Error GoTo fokop
GlobalDatabaseName = CD.FileName
If GlobalDatabaseName = "" Then
Exit Sub
End If
Dim MyDB As Database, thesql As String, theset As Recordset
Set MyDB = OpenDatabase(GlobalDatabaseName)
thesql = "SELECT * FROM HeaderData"
Set theset = MyDB.OpenRecordset(thesql)
If theset.EOF = False Then
theset.MoveFirst
Text21.Text = Replace(FixNull(theset.Fields(0).Value), "@@@", "")
Text22.Text = Replace(FixNull(theset.Fields(1).Value), "@@@", "")
Text23.Text = Replace(FixNull(theset.Fields(2).Value), "@@@", "")
DTPicker1.Value = FixNull(theset.Fields(3).Value)
DTPicker1.Value = FixNull(theset.Fields(4).Value)
Text24.Text = Replace(FixNull(theset.Fields(5).Value), "@@@", "")
Text25.Text = Replace(FixNull(theset.Fields(6).Value), "@@@", "")
Text26.Text = Replace(FixNull(theset.Fields(7).Value), "@@@", "")
Text1.Text = Replace(FixNull(theset.Fields(8).Value), "@@@", "")
End If
theset.Close
thesql = "SELECT AssemblyName FROM SparesData GROUP BY [AssemblyName]"
Set theset = MyDB.OpenRecordset(thesql)
If theset.EOF = False Then
Combo1.Clear
theset.MoveFirst
Do While theset.EOF = False
Combo1.AddItem theset.Fields(0).Value
theset.MoveNext
Loop
Combo1.Text = Combo1.List(0)
End If
theset.Close
thesql = "SELECT * FROM AnalysisTeam"
Set theset = MyDB.OpenRecordset(thesql)
If theset.EOF = False Then
theset.MoveFirst
k = 0
Do While theset.EOF = False
k = k + 1
FGATeam.TextMatrix(k, 0) = Replace(theset.Fields(0).Value, "@@@", "")
FGATeam.TextMatrix(k, 1) = Replace(theset.Fields(1).Value, "@@@", "")
FGATeam.TextMatrix(k, 2) = Replace(theset.Fields(2).Value, "@@@", "")
theset.MoveNext
Loop
End If
theset.Close
Frame2.Visible = True
SparesMain.Caption = "Spares Definition (" & GlobalDatabaseName & ")"
Call LoadTreeFromAccess
Call FixTreeText
StatusBar1.Panels(2).Text = "File loaded successfully."
Exit Sub
Canceled:
msgbox "Canceled!"
exit sub
fokop:
StatusBar1.Panels(2).Text = "Unable to perform operation."
Call FileExport_Click
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|