473,320 Members | 1,867 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,320 software developers and data experts.

Calling vb from other application

I would like to run a function of one access file from another
access/excel file, How can i do that?

For example: I want to write a procedure in Excel VB that will call
another function in an access file (suppose i want to call an update vb
procedure in access that will update the data in the access file so i
can read it from the Excel. The user will only have to get to the Excel
file and not the Access file.)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
3 1810
Gal merom <ga***@towersemi.com> wrote in message news:<40*********************@news.frii.net>...
I would like to run a function of one access file from another
access/excel file, How can i do that?

For example: I want to write a procedure in Excel VB that will call
another function in an access file (suppose i want to call an update vb
procedure in access that will update the data in the access file so i
can read it from the Excel. The user will only have to get to the Excel
file and not the Access file.)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


From within Excel's VBA, you could use the DAO Object model to access
an MS Access database and then execute the desired module. Or you
could instantiate an MS Access database object within the Excel VBA
code and then use the object with its methods. Of course, this
assumes that you know the full path and filename of the access
database to open and that you have permissions to do so.

Check the Online help for information regarding DAO.

Cheers,
Steve Cummings
Nov 12 '05 #2
Thanks Steve
I did try reading all the help files that i can find on DAO. I could
call tables,queries but i don't find the object to call for running a VB
code. Can you please write down just one line example to show me how to
call a function called XXX after creating the DAO object.
Thanks
Gal

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
"Gal merom" <ga***@towersemi.com> wrote in message
news:40*********************@news.frii.net...
Thanks Steve
I did try reading all the help files that i can find on DAO. I could
call tables,queries but i don't find the object to call for running a VB
code. Can you please write down just one line example to show me how to
call a function called XXX after creating the DAO object.
Thanks
Gal

This example assumes you have a database "C:\Test.mdb" with a table
tblPersons with fields PsnID = Autonumber, PsnFirstName, PsnLastName and you
have a few sample rows. The code written within your Excel workbook will
change the surname of person number 2 to whatever is in the current (active)
cell.

It is not necessarily the way I would actually do this task, but since you
don't say exactly what you are doing I have given an example which makes use
of DAO recordsets. Note that when you paste this code into Excel, make sure
that you choose Tools>References and select Microsoft DAO 3.6 Object Library
and make sure it compiles (Debug>Compile)

Another point to note is that if you are just trying to keep a database and
a spreadsheet synchronized, then sometimes using a linked table in Access
can be very useful as it simply looks up the live data from Excel. This
means you don't have to write any code. Anyway...

Public Sub UpdateRow()

On Error GoTo Err_Handler

Dim dbe As DAO.DBEngine
Dim wks As DAO.Workspace
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strPath As String
Dim strSQL As String
Dim strLastName As String

strLastName = Trim$(Application.ActiveCell)

strPath = "C:\Test.mdb"

strSQL = "SELECT * FROM tblPersons WHERE PsnID = 2"

Set dbe = New DBEngine

Set dbs = dbe.Workspaces(0).OpenDatabase(strPath)

Set rst = dbs.OpenRecordset(strSQL)

If Not rst.EOF Then

rst.Edit

If Len(strLastName) > 0 Then
rst!PsnLastName = strLastName
Else
rst!PsnLastName = Null
End If

rst.Update

MsgBox "Record Updated", vbInformation

Else

MsgBox "Person not found", vbExclamation

End If
Exit_Handler:

On Error Resume Next

If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

If Not dbe Is Nothing Then
Set dbe = Nothing
End If

Exit Sub

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub


Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Paul | last post by:
Hi, In SQL Books Online in the section on @@Error it gives the following example: -- Execute the INSERT statement. INSERT INTO authors (au_id, au_lname, au_fname, phone, address, city,...
5
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have...
7
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is...
6
by: Jon Hyland | last post by:
Ok, I'm a little rusty on this, it should be a simple problem but I can't figure it out. How can I handle form events in my main code page?? I'm creating a Windows App in C#. Rather than make...
15
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
5
by: joeblast | last post by:
I have a Web service that gets the financial periods and hold a reference to a disconnected dataset built at initialization. Web methods work on the dataset inside the web service. Everything is...
11
by: briankirkpatrick | last post by:
Forgive me if my post seems a little amateurish... I'm requesting assistance from some of you smart folks out there to get the managed calls write that meet the specification in the esa.h for...
12
by: tom_kuehnert | last post by:
Hi! I'm trying to execute a program using system(). The program itself is located in some path which might contain whitespaces. Simple solution would be this: system("\"C:\A B\C.exe\""); ...
16
by: Jaco Naude | last post by:
Hi there, This is my first post over here and I hope someone can give me some guidance. I'm trying to embed Python into a Visual C++ 2008 application and I'm getting linker problems. I've...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.