|
-
Sep 22nd, 2000, 11:41 AM
#1
Thread Starter
Junior Member
How do i set the database accessed by data1 to what the user chooses in a file open dialog box? Also, where is there any information on using the api to display a file open dialog box rather than a commondialog box as this takes up more memory from what i have read.
Thanks in advance
If you reach total enlightenment while drinking a beer, I bet it makes beer shoot out your nose.
VB5 Enterprise SP3
-
Sep 22nd, 2000, 11:46 AM
#2
Frenzied Member
I'm sorry but I don't know too much about DataBases is it not Data1.Database or Data1.Path = CommonDialog1.FileName? I can't test it now but you should take a look at the properties, but for your second prob I got an answer.
http://www.vb-world.net/articles/commondialog/
and VbNet will help ya with lots of example of the Common Dialog (positioning and complicated stuff)
http://www.mvps.org/vbnet/
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Sep 22nd, 2000, 11:53 AM
#3
_______
<?>
First Part of Question:
Code:
Private Sub Command2_Click()
'display the commondialog show open
CommonDialog1.InitDir = "C:\" 'set dir path
CommonDialog1.CancelError = True 'used in cancel code
CommonDialog1.Filter = "All files(*.*)|*.*" 'filter for all files
CommonDialog1.ShowOpen 'show files
Data1.Database = CommonDialog1.FileName
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 22nd, 2000, 01:19 PM
#4
Fanatic Member
Yep, the GetOpenFileName() API does the thing:
Code:
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
Private Sub Form_Load()
Dim OFName As OPENFILENAME
OFName.lStructSize = Len(OFName)
'Set the parent window
OFName.hwndOwner = Me.hWnd
'Set the application's instance
OFName.hInstance = App.hInstance
'Select a filter
OFName.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
'create a buffer for the file
OFName.lpstrFile = Space$(254)
'set the maximum length of a returned file
OFName.nMaxFile = 255
'Create a buffer for the file title
OFName.lpstrFileTitle = Space$(254)
'Set the maximum length of a returned file title
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = "C:\"
'Set the title
OFName.lpstrTitle = "Please select a file to open..."
'No flags
OFName.flags = 0
'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then
MsgBox "File to Open: " + Trim$(OFName.lpstrFile)
Else
MsgBox "Cancel was pressed"
End If
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
|