PC Review


Reply
Thread Tools Rate Thread

Add new record to Access using VBA in excel

 
 
Sue
Guest
Posts: n/a
 
      1st Feb 2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
add new excel row, when a new access record is added. John Evans Microsoft Access 2 23rd Nov 2008 10:33 PM
How to save a record in access to a new row in Excel =?Utf-8?B?SmFuaXM=?= Microsoft Access VBA Modules 1 6th Nov 2007 05:08 PM
Excel to Access create new record Little Penny Microsoft Excel Programming 0 9th Sep 2007 05:05 AM
Find Record in Access Using Excel =?Utf-8?B?Tm9lbWk=?= Microsoft Excel Programming 1 20th Feb 2007 02:49 AM
Update Access tables from excel if record exists else add new record Diti Microsoft Access External Data 0 30th Sep 2005 02:51 PM


Features
 

Advertising
 

Newsgroups
 


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