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 : - Private Sub Command2_Click()
-
-
Dim fDialog As Office.FileDialog
-
Dim varFile As Variant
-
-
' Clear listbox contents. '
-
Me.List3.RowSource = ""
-
-
-
' Set up the File Dialog. '
-
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
-
-
With fDialog
-
-
' Allow user to make multiple selections in dialog box '
-
.AllowMultiSelect = False
-
-
' Set the title of the dialog box. '
-
.Title = "Please select Access database"
-
-
' Clear out the current filters, and add our own.'
-
.Filters.Clear
-
.Filters.Add "Access Databases", "*.ACCDB"
-
.Filters.Add "All Files", "*.*"
-
-
' Show the dialog box. If the .Show method returns True, the '
-
' user picked at least one file. If the .Show method returns '
-
' False, the user clicked Cancel. '
-
If .Show = True Then
-
-
'Loop through each file selected and add it to our list box. '
-
For Each varFile In .SelectedItems
-
Me.List3.AddItem varFile
-
-
Next
-
-
-
Else
-
MsgBox "You clicked Cancel in the file dialog box."
-
End If
-
End With
-
End Sub
-
-
-
-
Private Sub Command5_Click()
-
-
'If IsNull(List3.Value) Then
-
'MsgBox "Please select the soruce file and try again.", vbOKOnly, "No file selected!"
-
'Else
-
-
Dim strSQL As String
-
Dim strvalue As String
-
-
strvalue = Me.List3.Value
-
-
strSQL = "INSERT INTO [Patient Level data]" & _
-
"SELECT *FROM [Patient Level data] t2 IN '" & strvalue & "'" & _
-
"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])))"
-
-
DoCmd.Hourglass True
-
'Turns off the Access warning messages
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL strSQL
-
DoCmd.Hourglass False
-
'Turns the Access warning messages back on
-
DoCmd.SetWarnings True
-
-
DoCmd.Close acForm, "Append", acSaveYes
-
DoCmd.OpenForm "WelcomePage"
-
-
'End If
-
-
End Sub
9 2204
After the file dialog populates the listbox, did you select a file from the listbox before clicking the button?
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
No, I mean did you physically click on one of the files in the listbox?
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
A listbox has no selected value unless you actually click on one.
so is there any other way to get the file path and database name from where I need to get the records
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.
I figured it out.
Thanks a lot for your help
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 :...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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,...
|
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...
| |