Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Access VB Help

Thread Tools
 
Search this Thread
 
Old 04 September 2003, 08:16 PM
  #1  
SinghSuperStud
Scooby Regular
Thread Starter
iTrader: (2)
 
SinghSuperStud's Avatar
 
Join Date: Jul 2001
Location: Walsall
Posts: 1,918
Likes: 0
Received 0 Likes on 0 Posts
Lightbulb

Hi !

is there any way I can use a macro or VB to move a set number of records from one table and append them to another ?

I have table of unallocated records which need to be allocated. I've done a form from which you select a name and check allocate. This should move records from the unallocated table to the allocated table and add the relevant name in one of the fields.

any help appreciated !

thanks, Jai
Old 04 September 2003, 11:16 PM
  #2  
Fatman
Scooby Regular
 
Fatman's Avatar
 
Join Date: Aug 2002
Posts: 2,390
Likes: 0
Received 0 Likes on 0 Posts
Post

You can run a predefined query from code, or even define, run and delete a query from code. How about...

SELECT your records and copy to a recordset
APPEND them to your target table
DELETE them from your source table

...or is that far too simplistic?
Old 05 September 2003, 08:19 AM
  #3  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

Fatman's suggestion will work providing you're not in a multi-user situation. If there is the potential for someone to update the table with an unallocated record, you need to delete from the original table where a unique identifier (eg primary key) is not in the allocated table.
Old 05 September 2003, 08:20 AM
  #4  
Fatman
Scooby Regular
 
Fatman's Avatar
 
Join Date: Aug 2002
Posts: 2,390
Likes: 0
Received 0 Likes on 0 Posts
Post

Doesn't Access have the ability to apply record locking?
Old 05 September 2003, 09:09 AM
  #5  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

should do, yes, but I'm unsure whether you can lock across queries hence the slight paranoia when it comes to deleting stuff
Old 08 September 2003, 03:24 PM
  #6  
SinghSuperStud
Scooby Regular
Thread Starter
iTrader: (2)
 
SinghSuperStud's Avatar
 
Join Date: Jul 2001
Location: Walsall
Posts: 1,918
Likes: 0
Received 0 Likes on 0 Posts
Post

thanks all !

Fatman - wat I'm after is the necessary code to do the select, append and delete functions as I'm fairly new so SQL and my knowldge of VB is somewhat limited. In particular, I only want to select a predefined number of records (50).

suggestions ?

thanks again

Jai
Old 09 September 2003, 01:14 PM
  #7  
GammonRoll
Scooby Regular
 
GammonRoll's Avatar
 
Join Date: Apr 2001
Posts: 242
Likes: 0
Received 0 Likes on 0 Posts
Post

Assuming I have grasped your requirement you need to right click the button and select build event, code builder. This should pull up the VB interface and assuming i've grasped it correctly the following should work:

Docmd.runsql("INSERT INTO tblAllocated SELECT * From TblUnallocated WHERE AllocatedFlag = True")
docmd.runSQL("DELETE * FROM tblUnallocated WHERE AllocatedFlag = TRUE")
This takes no account of record locking or hiding of user messages. Is this what you're looking for? If not, them PM me and I'll see if I can help.

Cheers,

Gamm
Old 09 September 2003, 03:02 PM
  #8  
Jza
Scooby Regular
 
Jza's Avatar
 
Join Date: Feb 2001
Posts: 2,959
Likes: 0
Received 0 Likes on 0 Posts
Post

You dont need a select and then append query - as the dude above says, you need to do an append. One thing you might want to do is clear the table you append to first - or if you dont have a table to append to - create a make-table query which does it for you. If you want to keep the table you created, just change the query from a make-table to an append (to the new table) query.

Try and get away from macros straight away - they are VERY BAD.... trust me - ive been using Access for 10 years

Create a module and put the code in there - with some sort of error trapping in!

Jza
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
JimBowen
ICE
5
02 July 2023 01:54 PM
TylerD529
General Technical
2
09 October 2015 01:53 AM
Littleted
Computer & Technology Related
4
25 September 2015 09:55 PM
Hangarrat93
Insurance
11
25 September 2015 08:42 AM
farmerwrx
Computer & Technology Related
14
10 September 2015 11:59 AM



Quick Reply: Access VB Help



All times are GMT +1. The time now is 05:01 PM.