LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Add new record to Access using VBA in excel

Hi there

I am slowly losing the will to live here!

Basically what I'm trying to do, is have text entered into a textbox
on an excel-based VBA-driven form, saved as a new record in a pre-
established table in Access (called tblProgramme, which has 3 columns:
an Autonumber, ProgrammeName and ProgrammeType). I then need the
database to refresh so that the new entry appears in another listbox,
allowing them to select it and associate it with the initiative they
are inputing information for.

I would also like the code to check that the text (which will be the
name of a new programme of work) isn't already in the table. In which
case, a msg box will tell the user "this item is already in the
list.." etc etc.

The small form with a textbox and command button on it appears when
the user clicks another command button ("Add New Programme Name") on
another form (Key Programmes).

While this should be simple, I just can't get it right and know I'm
overlooking something? Undoubtedly has something to do with the fact
that I have indicated where I want the record saved???



Here's what I have so far:

In a separate module (public_var) I have:

Sub FindDatabasePath()

path1 = "\\xxxxxxxxx\xxxxxxxx\xxxxxxx\xxx\xxxxxxxxx"
path1 = "" & path1 & "" & "\xxxxxxxx - xxxxxxxxxx Database.mdb"

End Sub

'-----------------------------------------------------------------

Private Sub cmbok_click()

Set ws = DBEngine.Workspaces(0)
Dim rsA As Recordset
Call FindDatabasePath
Set db = ws.OpenDatabase(path1)

Call SaveR

rsA.Update
rsA.Close
db.Close

Set rsA = Nothing
Set db = Nothing

Unload frmAddProgramme
frmStrategy.Show

End Sub

'-----------------------------------------------------------------

Private Sub SaveR()
Dim MyObject As Object
Set MyObject = txOverallProgramme

With frmAddProgramme

..txOverallProgramme = CheckBlank(rsA.Fields(2))

End With
End Sub

'-----------------------------------------------------------------

Function CheckBlank(chkvl As Variant)

If chkvl = "" Then

CheckBlank = Null
Else

CheckBlank = chkvl

End If
End Function


Any help would be truly appreciated!

Thanks in advance,
Sue
 
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
Excel to Access create new record Little Penny Excel Programming 0 September 9th 07 05:05 AM
Update current record in Access using Excel Noemi Excel Programming 1 February 21st 07 02:38 PM
Find Record in Access Using Excel Noemi Excel Programming 1 February 20th 07 02:49 AM
New record in table in Access from VBA in Excel JCanyoneer Excel Programming 5 March 24th 05 08:26 AM
Modifying an Access record in Excel John Moll Excel Programming 1 August 1st 03 05:27 PM


All times are GMT +1. The time now is 12:10 PM.

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"