473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How do I Use the FileDialog Control Properly

5
Hi,

I need your expert advise on MS access/VB issue. I am very much new to Access and VB programming. I have created a Access database to store information of the children assessed for preventive dental treatment. This database will be used by various field nurses to collect the data. Eventually, after certain period of time, these different databases will be combined to create a master database. And this master database will be updated with new records periodically. I have created one form in the master database where user can select 'field(client) database and append records to master database. I used listbox to select the access database file. The issue is when I select the file via Office.FileDialog then try to append the records, a VB error message appears saying 'invalid use of null'. It appears that the value of listbox is null even though I have selected the file.

I would really appreciate if you could help me figure out what is wrong with code

Here is my code :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2.  
  3.    Dim fDialog As Office.FileDialog
  4.    Dim varFile As Variant
  5.  
  6.    ' Clear listbox contents. '
  7.    Me.List3.RowSource = ""
  8.  
  9.  
  10.    ' Set up the File Dialog. '
  11.    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
  12.  
  13.    With fDialog
  14.  
  15.       ' Allow user to make multiple selections in dialog box '
  16.       .AllowMultiSelect = False
  17.  
  18.       ' Set the title of the dialog box. '
  19.       .Title = "Please select Access database"
  20.  
  21.       ' Clear out the current filters, and add our own.'
  22.       .Filters.Clear
  23.       .Filters.Add "Access Databases", "*.ACCDB"
  24.       .Filters.Add "All Files", "*.*"
  25.  
  26.       ' Show the dialog box. If the .Show method returns True, the '
  27.       ' user picked at least one file. If the .Show method returns '
  28.       ' False, the user clicked Cancel. '
  29.       If .Show = True Then
  30.  
  31.          'Loop through each file selected and add it to our list box. '
  32.          For Each varFile In .SelectedItems
  33.             Me.List3.AddItem varFile
  34.  
  35.          Next
  36.  
  37.  
  38.       Else
  39.          MsgBox "You clicked Cancel in the file dialog box."
  40.       End If
  41.    End With
  42. End Sub
  43.  
  44.  
  45.  
  46. Private Sub Command5_Click()
  47.  
  48. 'If IsNull(List3.Value) Then
  49. 'MsgBox "Please select the soruce file and try again.", vbOKOnly, "No file selected!"
  50. 'Else
  51.  
  52. Dim strSQL  As String
  53. Dim strvalue As String
  54.  
  55. strvalue = Me.List3.Value
  56.  
  57. strSQL = "INSERT INTO [Patient Level data]" & _
  58. "SELECT *FROM [Patient Level data] t2 IN '" & strvalue & "'" & _
  59. "WHERE NOT EXISTS ( SELECT*FROM [Patient Level data] t1 WHERE ((t2.PatientID<>t1.[PatientID]) AND (t2.First_Name=t1.[First_Name]) AND (t2.[Last Name]=t1.[Last Name])))"
  60.  
  61. DoCmd.Hourglass True
  62.         'Turns off the Access warning messages
  63.         DoCmd.SetWarnings False
  64.             DoCmd.RunSQL strSQL
  65.     DoCmd.Hourglass False
  66.         'Turns the Access warning messages back on
  67.         DoCmd.SetWarnings True
  68.  
  69. DoCmd.Close acForm, "Append", acSaveYes
  70. DoCmd.OpenForm "WelcomePage"
  71.  
  72. 'End If
  73.  
  74. End Sub
Jan 23 '12 #1
9 2204
Rabbit
12,516 Expert Mod 8TB
After the file dialog populates the listbox, did you select a file from the listbox before clicking the button?
Jan 23 '12 #2
San134
5
Hi Rabbit,

Thanks for your quick reply.

Yes, I tried to selecting the item with as follow

strvalue = List3.Selected(0)

but it doesn't work


-San
Jan 23 '12 #3
Rabbit
12,516 Expert Mod 8TB
No, I mean did you physically click on one of the files in the listbox?
Jan 23 '12 #4
San134
5
I don't want it to be physically selected. If I select the file via FileDialog I need the value of list box to be that file path.

Thanks
Jan 23 '12 #5
Rabbit
12,516 Expert Mod 8TB
A listbox has no selected value unless you actually click on one.
Jan 23 '12 #6
San134
5
so is there any other way to get the file path and database name from where I need to get the records
Jan 23 '12 #7
Rabbit
12,516 Expert Mod 8TB
You can use the ItemData property of the listbox to iterate through all items in the listbox. But if the goal is to go from file dialog to insert, you can skip the listbox altogether and just use the results from the file dialog.
Jan 23 '12 #8
San134
5
I figured it out.

Thanks a lot for your help
Jan 23 '12 #9
NeoPa
32,556 Expert Mod 16PB
You may find Select a File or Folder using the FileDialog Object helpful, though Rabbit seems to have helped with your basic confusion already.
Jan 23 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Lig | last post by:
We have an implementation of Oracle 9i database. We have a team of 20 developers working on a project. We use PL/SQL DEVELOPER and Visual Source Safe to cotrol the source. The problem we have at...
1
by: mjcast | last post by:
I have been working on an ActiveX control in C#. It is packaged in a Windows Control library and the code is in a user control. The control is used as an automation receiver that is used to update a...
1
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside...
10
by: ej1008 | last post by:
HI all I am having a windows Control running on ASP.Net webform. From this windows control I am trying to connect to database to do some database operations. Now I am facing problem while...
3
by: I am Sam | last post by:
I keep getting the following error message when I try to iterate through a CheckBoxList control: Object reference not set to an instance of an object. Description: An unhandled exception...
1
by: Tuong | last post by:
I have a situation where i have a form that contains a webbrowser control. With this I was able to implement an application that can browse websites. One particular website i visited opens up...
0
by: PhilC | last post by:
I'm not sure what I'm doing wrong here... I've created a web parts zone, and a catalog zone. Now if I create a very simple user control called "Tester": public partial class Tester :...
0
by: =?Utf-8?B?ams=?= | last post by:
Hello all, I have previously posted on problem i was facing related to use of Process.Start to open a word document. On further investigation, its more of a problem with where the executable...
2
by: fredloh | last post by:
i have a microsoft date and time picker on a form. when i open the form on the pc where the form was created, the form opens and display the control properly. however, it opens just fine in some...
4
by: LadyReader | last post by:
I have an Access2003 db that was converted from an Access2000 db. I would like to add a FileDialog control to a form but I don't see it in the Toolbox. I added a reference to Miscrosoft Office...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.