Invoking The 'login To A SQL Server Connection' Dialog

Aug 30, 2005

Hello again,

I have a MS Access project that uses a SQL Server connection to retrieve data. It is set up to authenticate the user every time the database is used, which is what I want it to to.

The problem is the timing of the dialog. In 'design mode', Access tries to show the Database window as soon as the file is loaded, realizes that it has to fetch data from the SQL connection, and prompts the user for the password - this is fine. However, the 'release version' has a different setup. Automatic showing of the database window is disabled, and the user controls the app via a customized menu instead. The result is that Access only prompts the user for his SQL Server credentials when a form is opened - this isn't OK. I would like Access to always ask for a SQL logon when the file is opened, even in 'release' mode.

I'm kinda new to using Access and SQL Server together, but I suppose there is some way of programatically invoking the dialog via a macro, right ? If so, what function should I use, and how do I make a macro that is run immediately after opening the file ?

It would also be nice if there was some way of detecting a successful logon, so that it can reinvoke the dialog indefinitely if logon fails.

Thanks for everything :)

View Replies


ADVERTISEMENT

Login SQL Server Linked Tables Automatic On Event Load Of Login Form

Apr 17, 2015

I have a ms access application in Front End and linked tables to sql server 2008 r2 in back end.. every time I open my application the linked tables ask to me for the user and password of the sql server user of the odbc conection. I want to connect to my sql database without login every time the user open the application, I know that can be possible if I start session from vba code...

View 2 Replies View Related

SQL Server Connection?

Jan 30, 2007

Hi all,

I have an .adp that works fine on a number of people's laptops.

One of the users however, keeps getting an error message stating that SQL Server does not exist or access has been denied.

This particular user is definitely setup on SQL Server with dbo permissions. She can also ping the server.

I have tried creating a DSN and this doesn't work either.

I am at a loss as to why this error message is occurring given that she can see the Server and has definitely been setup.

Do you have any suggestions?

Thanks,
Kabir

View 1 Replies View Related

Connection Between SQL Server And MS Access

Jun 17, 2006

Hi :

I have a question of the connection between SQL Server and MS Access.

I have a project, which is using SQL Server as backend, we use MS Access forms as the frontend.

Firstly, I created the datbase (db1) in the SQL Server, and create a few tables in db1. And then, I create a few forms in the MS Access, I used ODBC connection to link tables from SQL Server to MS Access, it is working fine. Those forms can access the linked tables.

After it is done, I put the MS Access database in the sharing drive, many people can share the files in this sharing drive.

When I go to my associate's computer, and then open the MS Access database in the sharing drive. The forms is working, but, it cannot access to linked tables from SQL Server.

I go back my computer again and then open the MS Access database, it is working fine.

What's the problem with it?
Does anybody need to install SQL Server software and also have db1 database in SQL Server and the path?

I want any user can access the linked tables from SQL Server, but I do NOT want any user can open the SQL Server and open the tables directly. I just want the users can access the linked tables through MS Access Forms only. Because I will make security in the MS Access. So, I don't let the users modify/open the tables in the MS Access, the users must access the tables via the forms only.

Please tell me the steps how to solve it.

Please help.

Thanks.

View 5 Replies View Related

Modules & VBA :: Check If There Is Connection To Server

Oct 8, 2013

In the code below I want to wait for ten seconds if there is connection to the server, if not to exit the sub with message "No connection to server". How to check it

Dim req As New XMLHTTP60
Dim resp As New DOMDocument60
Dim xmlNodeList As IXMLDOMNodeList
Dim myNode As IXMLDOMNode
Dim xmlNode As IXMLDOMNode
Dim presription As IXMLDOMNode

req.Open "GET", "https://api.zdravstvo.gov.mk/rest/prescriptions/" & Me.br_recept, False
req.send
resp.LoadXML req.responseText

View 2 Replies View Related

Remote Deskptop Connection To Access DB On Server

Apr 10, 2007

HiI currently have an Access Database in a BE/FE, server/client LAN architecture at a single office location. My client would like to allow one user to 'add new records' to the database on the weekends (i.e. after hours), without needing to come into the office.From my research, it seems I can setup Remote Desktop to connect from the client's home PC directly to the server PC, across the internet, using Windows XP Professional on both computers. Is it that simple, or should I be considering other things?

View 5 Replies View Related

Modules & VBA :: How To Check If Connection To SQL Server Established

Apr 8, 2014

How I can check if connection to SQL server is established with VBA before the SQL is executed. btw I use VPN connection to connect to sql server, and some times VPN connection is going down in middle of work and it is quite unconvinced.

View 2 Replies View Related

General :: Invoking On Screen Keyboard In Window 8 From Access

Apr 18, 2014

Is there anyway to bring up the on screen keypad or on screen keyboard from Access when running Windows 8 on the desktop? It would really be useful if someone was on a tablet wanting to input data in a text box if could automatically invoke the onscreen keyboard. By default when running applications on the desktop in Windows 8, one has to manually bring it up. I would like to include a touch option so every time wanted to enter data, they would not have to manually touch display keyboard option. A number pad like in excel for iPad would be even better. If text field would bring up keyboard, if number field, it would bring up number pad.

View 6 Replies View Related

Forms :: Login Form On Opening Access Asking For Password And Login Name

Jun 17, 2013

I have access 2010, I currently have a database in place and operational. What I am wondering is there a way to have a form come up whenever someone opens access and asks for a password and login name. Also I would like to have a 2 tier system. One for Admins and the other for users with limited access.

Is this even possible to accomplish?

View 2 Replies View Related

How To Establish The Connection Between Ms-Access2000 & Oracle Using DAO Connection?

Sep 26, 2005

Dear Guys,
How to Establish the connection between Ms-Access2000 & Oracle using DAO Connection through Code?.

I created one table in Oracle and I created User-DSN in ODBC.
I linked that oracle table into Ms-Access MDB using Link table option in ms-Access.

Now, Whenever I open that mdb, we need to establish the ODBC connectivity automatically through code (I mean, we need to refresh automatically).

I need to hardcode all the information in the Ms-Access code.

My User DSN Name: abcd
Oracle Database Name: abcd
Schema Name(User Name): abcd
password: abcd

View 1 Replies View Related

DNS Connection --> DNSless Connection

Jan 9, 2005

Right Ok i hope i can get some help cause im absolutely stumped..
i cant get my login page to work since moving it from my PWS(iis on xp) DSN connection
to a 24/7 server on the net with DSNless connection
here is the code for the include file "conntopwd.asp"
http://www.pritchardwebdesign.pwp.blueyonder.co.uk/conntopwd.txt
the username and path has been changed slightly for security purposes,
and the code for the login page which attempts to access the database is here
http://www.pritchardwebdesign.pwp.blueyonder.co.uk/login.txt
the connection has been tested by one of the tech support guys at brinkster and he told me it was ok,
the problem was the way that the data is called from the data base is wrong ..
The tech support guy said that it was this line that was causing the problem..
MM_rsUser.ActiveConnection = MM_conntopwd_STRING
Any help would be much appreciated as im stuck for now..

View 2 Replies View Related

Dialog Box

Oct 10, 2005

Hi All.
I created query with dialog box in Access :
SELECT (Format([Date_P],"mmm yyyy")) AS [Date_P], Result, Count([Date_P]) AS Pos
FROM ABC
GROUP BY (Format([Date_P],"mmm yyyy")), Result, Format([Date_PAP],"yyyy")
HAVING Result<>"neg" AND Count(Date_P>0
AND (Format([Date_P],"yyyy")=[Please, enter year (yyyy):]);
How to convert that query to veiw MS SQL?
Thank.

View 1 Replies View Related

Dialog Box Path

Oct 21, 2005

Hi all,

Can I set the default path for a dialog box to look in when called?

View 1 Replies View Related

Get Rid Of Startup Dialog?

Aug 10, 2007

How do I get rid of the start up dialog? The boxes which pop up and say "Security warning, Unsafe expressions not blocked" and the other that says "warning this document may not be safe blah blah blah".

Thank you for the help :)

View 14 Replies View Related

Progress Dialog

Nov 19, 2004

Hi,
I have a report and I am doing some SQL stuff at the back end on the report open. This takes a little time and I want to show the user that its working and I want to prevent him from double clicking the report again. So is there any way to show a progress dialog or something so that the user knows that the list is being built? Thanks in advance!
Adwait

View 1 Replies View Related

Dialog Box For Hyperlinks

Jul 3, 2013

I am in the process of creating d/base of early settlers for our local museum. The Fields need to have reference to one or more files or programs outside of Access, e.g. Legacy, Word, photo files, d/bases of electoral rolls, etc.
The apparent easy solution was to attach these sources and I also got a handy Attachments dialog box that showed me the list of attachments for a every person or place. However, after entering only 10 names and attachments, the file size had grown to nearly 8Mb - obviously impracticable if the d/base is to contain over 2,000 names.

So, I switched to using Hyperlinks which cut the file size by 90% but now I have another problem: Hyperlinks only lead to one item, e.g. a photo, whereas the person concerned may have several photos and several other references. This would necessitate creating multiple Fields.

Is there a way to create a Dialog box (similar to the Attachments box) that would show me a list of the Hyperlinks for a particluar person?

View 3 Replies View Related

Cannot Invoke Common Dialog

Nov 27, 2005

I am trying to add a common dialog to my form from the toolbox and get the following error 'you dont have the license required to use this ActiveX control. Is there any way I can sort this out? I am using Access 2002. I am getting desperate and any help would be much appreciated

View 3 Replies View Related

Printer Dialog Box Before PRINT

Nov 15, 2006

Hi,

I used the code below to hide all the toolbars and then created my custom ReportToolbar so the user can print the report. All works OK; however, the PRINT button on my custom toolbar sends the report imidiately to the printer. How can I create a button that I could add to my custom toolbox which would open the dialog box that allows to choose the printer, number of pages to print, etc.. (same action as I can get by going to File->Print)?

PS> Also, is there any way to remove the drop down arrow from my custom toolbox? I disabled Customize Toolbox but the pulldown arrow still appears. I found making an MDE would take care of this, but was wondering if there was another solution.

Code used to hide toolbars:For i = 1 To CommandBars.Count
CommandBars(i).Enabled = False
Next i

View 3 Replies View Related

Disabling Parameter Dialog Box

Mar 17, 2006

Hello,
I have an innoccuous problem with a report I run in Access. The record source for the report is a query that is pulls data from 6 tables. I have a table titled ARInfo that I have to return amost all the fields in the table (big table) so I used * and show all the fields. When I run the report from the button click event on my form, before the query runs that servers as the report's record source, a parameter dialog box pops up titled ARInfo (table name). You do not have to enter anything in the box for the report to run properly. I have only been with the company or 3 months, but we have used Aceess 97 and Access 2000 in the past and it is my understanding that in the old systems, this dialog would not pop up (The query, form, report, and code is unchanged0. Since we converted to Access 2002, this dialog pops up. The code behind the form, report, and in the associated modules is very immense (This report and form that drives it touches many diferent pieces of the system) so I'm not really about to inclued any code in this post. If anybody knows a quick and dirty trick to disable dialogs or any conceptual theories as to why this is occuring, please let me know.
Andrew

View 2 Replies View Related

Dialog Box To Save Data Changes?

Mar 11, 2005

Hi everyone,

I have a client I'm currently working for that has dumped Access on me. I'm not originally here for Access and am sort of learning as I go along (I'm here to setup, run, and maintain servers, etc.)

The problem is they have a large contact database in Access, and want the forms to pop up a dialog asking if data changes are okay before actually updating. I know that Access normally just does the change, but there is an issue with someone that doesn't understand computers at all making a mess of it (adding in one client 15 times, each with one different piece of information, erasing things in an attempt to search, etc, etc.)

I've been going all over the place trying to research the issue for hours and have had no luck finding a solution. Any help would be beyond appreciated. Thanks in advance for any help!

-Walter

View 8 Replies View Related

Input Dialog Box Help Needed

Aug 5, 2005

i need to find out how can i have a popup dialog box where they can enter in a value and the value must then populate to a non enabled field on a form. This is my trigger field and has to be filled in but they tend to forget this what i want to do is put a dialog box where they will enter their id and that id must then populate into a id field on the form which is disabled any help will be appreciated

thanks mel :)

View 1 Replies View Related

Input Dialog Box Help Needed

Aug 5, 2005

i need to find out how can i have a popup dialog box where they can enter in a value and the value must then populate to a non enabled field on a form. This is my trigger field and has to be filled in but they tend to forget this what i want to do is put a dialog box where they will enter their id and that id must then populate into a id field on the form which is disabled any help will be appreciated

thanks mel :)

View 5 Replies View Related

File Browse Dialog Box....

Jun 14, 2006

I have a field in a form to which I wish to be able to browse to a particular PDF file. This location is then to be a hyperlink that when clicked upon, it will open the chosen file.

I have seen a thread already for file browsing, but it said to look at the VBA code, which I have no idea what it means :(

Please help, this is driving me mad.

TIA

RD

View 3 Replies View Related

SaveAs Option Pop-up Dialog Box

Oct 18, 2004

I've written a function which generates a MailMerge in Word from Access. Works great. However, Id there an easy way to get the SaveAs dialog box to pop up so the user can choose where to save the resulting doc? Thanks.

View 1 Replies View Related

Open File Dialog

Oct 26, 2006

Another question:

I used the suggested code from this forum to import a file with the open file dialog box. It works great to that point, but how do I specify which table I want it to populate with this data?? Thanks!

Here's the code:

vb Code: Original - vb Code Type tagOPENFILENAMElStructSize As LonghwndOwner As LonghInstance As LongstrFilter As StringstrCustomFilter As StringnMaxCustFilter As LongnFilterIndex As LongstrFile As StringnMaxFile As LongstrFileTitle As StringnMaxFileTitle As LongstrInitialDir As StringstrTitle As StringFlags As LongnFileOffset As IntegernFileExtension As IntegerstrDefExt As StringlCustData As LonglpfnHook As LonglpTemplateName As StringEnd TypeDeclare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As BooleanDeclare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As BooleanDeclare Function CommDlgExtendedError Lib "comdlg32.dll" () As LongGlobal Const ahtOFN_READONLY = &H1Global Const ahtOFN_OVERWRITEPROMPT = &H2Global Const ahtOFN_HIDEREADONLY = &H4Global Const ahtOFN_NOCHANGEDIR = &H8Global Const ahtOFN_SHOWHELP = &H10' You won't use these.'Global Const ahtOFN_ENABLEHOOK = &H20'Global Const ahtOFN_ENABLETEMPLATE = &H40'Global Const ahtOFN_ENABLETEMPLATEHANDLE = &H80Global Const ahtOFN_NOVALIDATE = &H100Global Const ahtOFN_ALLOWMULTISELECT = &H200Global Const ahtOFN_EXTENSIONDIFFERENT = &H400Global Const ahtOFN_PATHMUSTEXIST = &H800Global Const ahtOFN_FILEMUSTEXIST = &H1000Global Const ahtOFN_CREATEPROMPT = &H2000Global Const ahtOFN_SHAREAWARE = &H4000Global Const ahtOFN_NOREADONLYRETURN = &H8000Global Const ahtOFN_NOTESTFILECREATE = &H10000Global Const ahtOFN_NONETWORKBUTTON = &H20000Global Const ahtOFN_NOLONGNAMES = &H40000' New for Windows 95Global Const ahtOFN_EXPLORER = &H80000Global Const ahtOFN_NODEREFERENCELINKS = &H100000Global Const ahtOFN_LONGNAMES = &H200000Function TestIt()Dim strFilter As StringDim lngFlags As LongstrFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _"*.MDA;*.MDB")strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:", _Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _DialogTitle:="Hello! Open Me!")' Since you passed in a variable for lngFlags,' the function places the output flags value in the variable.Debug.Print Hex(lngFlags)End FunctionFunction GetOpenFile(Optional varDirectory As Variant, _Optional varTitleForDialog As Variant) As Variant' Here's an example that gets an Access database name.Dim strFilter As StringDim lngFlags As LongDim varFileName As Variant' Specify that the chosen file must already exist,' don't change directories when you're done' Also, don't bother displaying' the read-only box. It'll only confuse people.lngFlags = ahtOFN_FILEMUSTEXIST Or _ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIRIf IsMissing(varDirectory) ThenvarDirectory = ""End IfIf IsMissing(varTitleForDialog) ThenvarTitleForDialog = ""End If' Define the filter string and allocate space in the "c"' string Duplicate this line with changes as necessary for' more file templates.strFilter = ahtAddFilterItem(strFilter, _"Access (*.mdb)", "*.MDB;*.MDA")' Now actually call to get the file name.varFileName = ahtCommonFileOpenSave( _OpenFile:=True, _InitialDir:=varDirectory, _Filter:=strFilter, _Flags:=lngFlags, _DialogTitle:=varTitleForDialog)If Not IsNull(varFileName) ThenvarFileName = TrimNull(varFileName)End IfGetOpenFile = varFileNameEnd FunctionFunction ahtCommonFileOpenSave( _Optional ByRef Flags As Variant, _Optional ByVal InitialDir As Variant, _Optional ByVal Filter As Variant, _Optional ByVal FilterIndex As Variant, _Optional ByVal DefaultExt As Variant, _Optional ByVal FileName As Variant, _Optional ByVal DialogTitle As Variant, _Optional ByVal hwnd As Variant, _Optional ByVal OpenFile As Variant) As Variant' This is the entry point you'll use to call the common' file open/save dialog. The parameters are listed' below, and all are optional.'' In:' Flags: one or more of the ahtOFN_* constants, OR'd together.' InitialDir: the directory in which to first look' Filter: a set of file filters, set up by calling' AddFilterItem. See examples.' FilterIndex: 1-based integer indicating which filter' set to use, by default (1 if unspecified)' DefaultExt: Extension to use if the user doesn't enter one.' Only useful on file saves.' FileName: Default value for the file name text box.' DialogTitle: Title for the dialog.' hWnd: parent window handle' OpenFile: Boolean(True=Open File/False=Save As)' Out:' Return Value: Either Null or the selected filenameDim OFN As tagOPENFILENAMEDim strFileName As StringDim strFileTitle As StringDim fResult As Boolean' Give the dialog a caption title.If IsMissing(InitialDir) Then InitialDir = CurDirIf IsMissing(Filter) Then Filter = ""If IsMissing(FilterIndex) Then FilterIndex = 1If IsMissing(Flags) Then Flags = 0&If IsMissing(DefaultExt) Then DefaultExt = ""If IsMissing(FileName) Then FileName = ""If IsMissing(DialogTitle) Then DialogTitle = ""If IsMissing(hwnd) Then hwnd = Application.hWndAccessAppIf IsMissing(OpenFile) Then OpenFile = True' Allocate string space for the returned strings.strFileName = Left(FileName & String(256, 0), 256)strFileTitle = String(256, 0)' Set up the data structure before you call the functionWith OFN.lStructSize = Len(OFN).hwndOwner = hwnd.strFilter = Filter.nFilterIndex = FilterIndex.strFile = strFileName.nMaxFile = Len(strFileName).strFileTitle = strFileTitle.nMaxFileTitle = Len(strFileTitle).strTitle = DialogTitle.Flags = Flags.strDefExt = DefaultExt.strInitialDir = InitialDir' Didn't think most people would want to deal with' these options..hInstance = 0'.strCustomFilter = ""'.nMaxCustFilter = 0.lpfnHook = 0'New for NT 4.0.strCustomFilter = String(255, 0).nMaxCustFilter = 255End With' This will pass the desired data structure to the' Windows API, which will in turn it uses to display' the Open/Save As Dialog.If OpenFile ThenfResult = aht_apiGetOpenFileName(OFN)ElsefResult = aht_apiGetSaveFileName(OFN)End If' The function call filled in the strFileTitle member' of the structure. You'll have to write special code' to retrieve that if you're interested.If fResult Then' You might care to check the Flags member of the' structure to get information about the chosen file.' In this example, if you bothered to pass in a' value for Flags, we'll fill it in with the outgoing' Flags value.If Not IsMissing(Flags) Then Flags = OFN.FlagsahtCommonFileOpenSave = TrimNull(OFN.strFile)ElseahtCommonFileOpenSave = vbNullStringEnd IfEnd FunctionFunction ahtAddFilterItem(strFilter As String, _strDescription As String, Optional varItem As Variant) As String' Tack a new chunk onto the file filter.' That is, take the old value, stick onto it the description,' (like "Databases"), a null character, the skeleton' (like "*.mdb;*.mda") and a final null character.If IsMissing(varItem) Then varItem = "*.*"ahtAddFilterItem = strFilter & _strDescription & vbNullChar & _varItem & vbNullCharEnd FunctionPrivate Function TrimNull(ByVal strItem As String) As StringDim intPos As IntegerintPos = InStr(strItem, vbNullChar)If intPos > 0 ThenTrimNull = Left(strItem, intPos - 1)ElseTrimNull = strItemEnd IfEnd FunctionPrivate Sub Command20_Click()Dim strFilter As StringDim strInputFileName As StringstrFilter = ahtAddFilterItem(strFilter, "CSV Files (*.csv)", "*.csv")strInputFileName = ahtCommonFileOpenSave( _Filter:=strFilter, OpenFile:=True, _DialogTitle:="Please select an input file...", _Flags:=ahtOFN_HIDEREADONLY)End Sub'This code was originally written by Ken Getz.'It is not to be altered or distributed,'except as part of an application.'You are free to use it in any application,'provided the copyright notice is left unchanged.'' Code courtesy of:' Microsoft Access 95 How-To' Ken Getz and Paul Litwin' Waite Group Press, 1996 Type tagOPENFILENAMElStructSize As LonghwndOwner As LonghInstance As LongstrFilter As StringstrCustomFilter As StringnMaxCustFilter As LongnFilterIndex As LongstrFile As StringnMaxFile As LongstrFileTitle As StringnMaxFileTitle As LongstrInitialDir As StringstrTitle As StringFlags As LongnFileOffset As IntegernFileExtension As IntegerstrDefExt As StringlCustData As LonglpfnHook As LonglpTemplateName As StringEnd Type Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _Alias "GetOpenFileNameA" (OFN As tagOPENFILENAME) As Boolean Declare Function aht_apiGetSaveFileName Lib "comdlg32.dll" _Alias "GetSaveFileNameA" (OFN As tagOPENFILENAME) As BooleanDeclare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long Global Const ahtOFN_READONLY = &H1Global Const ahtOFN_OVERWRITEPROMPT = &H2Global Const ahtOFN_HIDEREADONLY = &H4Global Const ahtOFN_NOCHANGEDIR = &H8Global Const ahtOFN_SHOWHELP = &H10' You won't use these.'Global Const ahtOFN_ENABLEHOOK = &H20'Global Const ahtOFN_ENABLETEMPLATE = &H40'Global Const ahtOFN_ENABLETEMPLATEHANDLE = &H80Global Const ahtOFN_NOVALIDATE = &H100Global Const ahtOFN_ALLOWMULTISELECT = &H200Global Const ahtOFN_EXTENSIONDIFFERENT = &H400Global Const ahtOFN_PATHMUSTEXIST = &H800Global Const ahtOFN_FILEMUSTEXIST = &H1000Global Const ahtOFN_CREATEPROMPT = &H2000Global Const ahtOFN_SHAREAWARE = &H4000Global Const ahtOFN_NOREADONLYRETURN = &H8000Global Const ahtOFN_NOTESTFILECREATE = &H10000Global Const ahtOFN_NONETWORKBUTTON = &H20000Global Const ahtOFN_NOLONGNAMES = &H40000' New for Windows 95Global Const ahtOFN_EXPLORER = &H80000Global Const ahtOFN_NODEREFERENCELINKS = &H100000Global Const ahtOFN_LONGNAMES = &H200000 Function TestIt()Dim strFilter As StringDim lngFlags As LongstrFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb)", _"*.MDA;*.MDB")strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")MsgBox "You selected: " & ahtCommonFileOpenSave(InitialDir:="C:", _Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _DialogTitle:="Hello! Open Me!")' Since you passed in a variable for lngFlags,' the function places the output flags value in the variable.Debug.Print Hex(lngFlags)End Function Function GetOpenFile(Optional varDirectory As Variant, _Optional varTitleForDialog As Variant) As Variant' Here's an example that gets an Access database name.Dim strFilter As StringDim lngFlags As LongDim varFileName As Variant' Specify that the chosen file must already exist,' don't change directories when you're done' Also, don't bother displaying' the read-only box. It'll only confuse people.lngFlags = ahtOFN_FILEMUSTEXIST Or _ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIRIf IsMissing(varDirectory) ThenvarDirectory = ""End IfIf IsMissing(varTitleForDialog) ThenvarTitleForDialog = ""End If ' Define the filter string and allocate space in the "c"' string Duplicate this line with changes as necessary for' more file templates.strFilter = ahtAddFilterItem(strFilter, _"Access (*.mdb)", "*.MDB;*.MDA")' Now actually call to get the file name.varFileName = ahtCommonFileOpenSave( _OpenFile:=True, _InitialDir:=varDirectory, _Filter:=strFilter, _Flags:=lngFlags, _DialogTitle:=varTitleForDialog)If Not IsNull(varFileName) ThenvarFileName = TrimNull(varFileName)End IfGetOpenFile = varFileNameEnd Function Function ahtCommonFileOpenSave( _Optional ByRef Flags As Variant, _Optional ByVal InitialDir As Variant, _Optional ByVal Filter As Variant, _Optional ByVal FilterIndex As Variant, _Optional ByVal DefaultExt As Variant, _Optional ByVal FileName As Variant, _Optional ByVal DialogTitle As Variant, _Optional ByVal hwnd As Variant, _Optional ByVal OpenFile As Variant) As Variant' This is the entry point you'll use to call the common' file open/save dialog. The parameters are listed' below, and all are optional.'' In:' Flags: one or more of the ahtOFN_* constants, OR'd together.' InitialDir: the directory in which to first look' Filter: a set of file filters, set up by calling' AddFilterItem. See examples.' FilterIndex: 1-based integer indicating which filter' set to use, by default (1 if unspecified)' DefaultExt: Extension to use if the user doesn't enter one.' Only useful on file saves.' FileName: Default value for the file name text box.' DialogTitle: Title for the dialog.' hWnd: parent window handle' OpenFile: Boolean(True=Open File/False=Save As)' Out:' Return Value: Either Null or the selected filenameDim OFN As tagOPENFILENAMEDim strFileName As StringDim strFileTitle As StringDim fResult As Boolean' Give the dialog a caption title.If IsMissing(InitialDir) Then InitialDir = CurDirIf IsMissing(Filter) Then Filter = ""If IsMissing(FilterIndex) Then FilterIndex = 1If IsMissing(Flags) Then Flags = 0&If IsMissing(DefaultExt) Then DefaultExt = ""If IsMissing(FileName) Then FileName = ""If IsMissing(DialogTitle) Then DialogTitle = ""If IsMissing(hwnd) Then hwnd = Application.hWndAccessAppIf IsMissing(OpenFile) Then OpenFile = True' Allocate string space for the returned strings.strFileName = Left(FileName & String(256, 0), 256)strFileTitle = String(256, 0)' Set up the data structure before you call the functionWith OFN.lStructSize = Len(OFN).hwndOwner = hwnd.strFilter = Filter.nFilterIndex = FilterIndex.strFile = strFileName.nMaxFile = Len(strFileName).strFileTitle = strFileTitle.nMaxFileTitle = Len(strFileTitle).strTitle = DialogTitle.Flags = Flags.strDefExt = DefaultExt.strInitialDir = InitialDir' Didn't think most people would want to deal with' these options..hInstance = 0'.strCustomFilter = ""'.nMaxCustFilter = 0.lpfnHook = 0'New for NT 4.0.strCustomFilter = String(255, 0).nMaxCustFilter = 255End With' This will pass the desired data structure to the' Windows API, which will in turn it uses to display' the Open/Save As Dialog.If OpenFile ThenfResult = aht_apiGetOpenFileName(OFN)ElsefResult = aht_apiGetSaveFileName(OFN)End If ' The function call filled in the strFileTitle member' of the structure. You'll have to write special code' to retrieve that if you're interested.If fResult Then' You might care to check the Flags member of the' structure to get information about the chosen file.' In this example, if you bothered to pass in a' value for Flags, we'll fill it in with the outgoing' Flags value.If Not IsMissing(Flags) Then Flags = OFN.FlagsahtCommonFileOpenSave = TrimNull(OFN.strFile)ElseahtCommonFileOpenSave = vbNullStringEnd IfEnd Function Function ahtAddFilterItem(strFilter As String, _strDescription As String, Optional varItem As Variant) As String' Tack a new chunk onto the file filter.' That is, take the old value, stick onto it the description,' (like "Databases"), a null character, the skeleton' (like "*.mdb;*.mda") and a final null character. If IsMissing(varItem) Then varItem = "*.*"ahtAddFilterItem = strFilter & _strDescription & vbNullChar & _varItem & vbNullCharEnd Function Private Function TrimNull(ByVal strItem As String) As StringDim intPos As IntegerintPos = InStr(strItem, vbNullChar)If intPos > 0 ThenTrimNull = Left(strItem, intPos - 1)ElseTrimNull = strItemEnd IfEnd Function Private Sub Command20_Click() Dim strFilter As String   Dim strInputFileName As String strFilter = ahtAddFilterItem(strFilter, "CSV Files (*.csv)", "*.csv")strInputFileName = ahtCommonFileOpenSave( _Filter:=strFilter, OpenFile:=True, _DialogTitle:="Please select an input file...", _Flags:=ahtOFN_HIDEREADONLY) End Sub 'This code was originally written by Ken Getz.'It is not to be altered or distributed,'except as part of an application.'You are free to use it in any application,'provided the copyright notice is left unchanged.'' Code courtesy of:' Microsoft Access 95 How-To' Ken Getz and Paul Litwin' Waite Group Press, 1996  


Thanks!!

KellyJo

View 1 Replies View Related

Open File Dialog Box

Mar 9, 2007

Hello,

I would like to put a cmdbutton on a form to open the File Dialog box directly from Access whereby users can search through folders and open a any file selected.
I have searched the web and found a link:

http://www.mvps.org/access/api/api0001.htm

I have copied the code into a module and the code behind the cmdbutton but getting an error.
Can anyone help me is finding a solution or an example? Thanks.

View 14 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved