Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 25th, 2007, 9:04 AM   #1
Abyss
Newbie
 
Join Date: Apr 2005
Posts: 18
Rep Power: 0 Abyss is on a distinguished road
Copying fields between two records

Hi guys,

I'm working with Access at the minute and have run into a problem. Basically, what I'm trying to do is create an 'add new record' button that will copy certain field values from the old record into the new record. For example

Quote:
Record #1: Name: Bateman Gender: Male MilesWalked: 3

Click new record button

New Record #2 Name: Bateman Gender: Male MilesWalked: blank
So in the first record the name, gender and mileswalked are typed in. Then the 'add new record' button is clicked and only the name and gender values are copied.

I'm trying to do this using and ADO recordset but not having much success. Any suggestions would be a help. Thanks!
Abyss is offline   Reply With Quote
Old Apr 25th, 2007, 9:12 AM   #2
pegasus001
Hobbyist Programmer
 
pegasus001's Avatar
 
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2 pegasus001 is on a distinguished road
If you have an database application do it using MsAccess. About the ADO arent you using querys to add values? Because ado.net is pretty straight forward and i would strongly reccomend switching to .net.
__________________
You never test the depth of a river with both feet.
The believer is happy. The doubter is wise.
Free speech carries with it some freedom to listen.
The next generation will always surpass the previous one. It`s one of the never ending cycles of life.
pegasus001 is offline   Reply With Quote
Old Apr 25th, 2007, 9:37 AM   #3
Abyss
Newbie
 
Join Date: Apr 2005
Posts: 18
Rep Power: 0 Abyss is on a distinguished road
Thanks for the reply, pegasus. I'm using MSAccess 2000 and VB 6. At present my code for the 'add new record' button looks like this:

Quote:
Private Sub cmdAddSameCase_Click()

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sSQL As String

On Error GoTo Err_cmdAddSameCase_Click


Set cn = CurrentProject.Connection

I've been experimenting with SELECT and INSERT functions here but haven't made much progress
sSQL = sSQL & " Month = " & Month.Value
sSQL = sSQL & " and Year = " & Year.Value
etc
etc

Set rs = cn.Execute(sSQL)


DoCmd.GoToRecord , , acNewRec

Exit_cmdAddSameCase_Click:
Exit Sub

Err_cmdAddSameCase_Click:
MsgBox Err.Description
Resume Exit_cmdAddSameCase_Click

End Sub
Unfortunately I can't switch to .net as I'm writing this piece of code for work.

As always, suggestions are much appreciated.
Abyss is offline   Reply With Quote
Old Apr 26th, 2007, 4:38 AM   #4
Abyss
Newbie
 
Join Date: Apr 2005
Posts: 18
Rep Power: 0 Abyss is on a distinguished road
Found a way to code this copy function. It's not so pretty but it works. If you're interested here's how I did it

Quote:
Private Sub cmdAddSameCase_Click()

On Error GoTo Err_cmdAddSameCase_Click

Dim txt1 As String, txt2 As String, txt3 As String, txt4 As String etc

txt1 = Me.Month.Value
txt2 = Me.Year.Value
txt3 = Me.centre.Value
txt4 = Me.Session.Value
etc
etc


DoCmd.GoToRecord , , acNewRec

Me.Month.Value = txt1
Me.Year.Value = txt2
Me.centre.Value = txt3
Me.Session.Value = txt4
etc
etc



Exit_cmdAddSameCase_Click:
Exit Sub

Err_cmdAddSameCase_Click:
MsgBox Err.Description
Resume Exit_cmdAddSameCase_Click

End Sub
Abyss is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
DNS SRV Records Dameon C# 0 Mar 17th, 2007 4:59 PM
Question about analyzing 6 million records Arla C# 11 Jun 22nd, 2006 3:02 PM
Multiple Units and Records Liens Delphi 4 Jan 22nd, 2006 7:07 AM
Type Mismatch - Deleting Records raikkonen ASP 1 Nov 16th, 2005 6:00 AM
How to force all form fields to be submitted aznluvsmc Perl 4 Oct 28th, 2005 6:30 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:23 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC