Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Update access DB record when finished running macro

Hi there,

I need an example macro that can create a new record in a shared
access database once the macro has finished running.

I would need the macro to enter the cell value from A1 for example in
a field and the date, time and if possible the username in another
field so four field in total,

I appreciate any help,

Thanks alot

Andrea

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Update access DB record when finished running macro

http://www.erlandsendata.no/english/...php?t=envbadac

Try the 2nd or 3rd link under "Document".

Hth,
Merjet


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Update access DB record when finished running macro

this could be a start
Private Sub ADOFromExcelToAccess()
'Make reference to Microsoft ActiveX Data Objects 2.8

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim r As Long


Set cn = New ADODB.Connection

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=\\Path To\your database\" _
& "mydatabaseName.mdb;Persist Security Info=False"

' open a recordset
Set rs = New ADODB.Recordset
rs.Open "DatabaseTable", cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table
r = 1 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("FieldName1") = Range("A" & r).Value
.Fields("FieldName2") = Range("B" & r).Value
.Fields("FieldName3") = Range("C" & r).Value
.Fields("FieldName4") = Range("D" & r).Value


' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

End Sub

" wrote:

Hi there,

I need an example macro that can create a new record in a shared
access database once the macro has finished running.

I would need the macro to enter the cell value from A1 for example in
a field and the date, time and if possible the username in another
field so four field in total,

I appreciate any help,

Thanks alot

Andrea


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Update access DB record when finished running macro

Thanks to both of you,

I'll have a look into it,

Andrea

On 22 Jun, 03:07, Mike wrote:
this could be a start
Private Sub ADOFromExcelToAccess()
'Make reference to Microsoft ActiveX Data Objects 2.8

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim r As Long

Set cn = New ADODB.Connection

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=\\Path To\your database\" _
& "mydatabaseName.mdb;Persist Security Info=False"

' open a recordset
Set rs = New ADODB.Recordset
rs.Open "DatabaseTable", cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table
r = 1 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("FieldName1") = Range("A" & r).Value
.Fields("FieldName2") = Range("B" & r).Value
.Fields("FieldName3") = Range("C" & r).Value
.Fields("FieldName4") = Range("D" & r).Value

' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

End Sub



" wrote:
Hi there,


I need an example macro that can create a new record in a shared
access database once the macro has finished running.


I would need the macro to enter the cell value from A1 for example in
a field and the date, time and if possible the username in another
field so four field in total,


I appreciate any help,


Thanks alot


Andrea- Hide quoted text -


- Show quoted text -



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
running the same record macro on different spreadsheets gwtechie72 New Users to Excel 2 November 18th 07 11:55 AM
Update current record in Access using Excel Noemi Excel Programming 1 February 21st 07 02:38 PM
Running UPDATE and APPEND queries from Access in Excel Amery Excel Programming 1 February 9th 07 01:20 AM
Update A Record In Access. Not Adding But Editing internacio[_2_] Excel Programming 0 January 31st 06 03:40 PM
How can I update an MS Access table record from within Execl works David Canfield Excel Discussion (Misc queries) 0 January 14th 05 08:51 PM


All times are GMT +1. The time now is 12:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"