![]() |
using debug.print
This might seem stupid, but I never used this command.
What I would like to do is that when I create a new record with DAO, I can get the autonumber of the created field to be put into a variable? I need this because data will be inputted in another table using the pk as fk. According to what I know, I need the debug.print to 'catch' the autonumber, however, I don't know how to do this... Can anyone help me on this? Just need to know how to retrieve the primary key of the created record... Thanks |
Hi Vince,
Debug.Print does is not used for "catching" variables, is merely outputs a value/formula result/text string to the "Immediate" pane in the VBE. When in the VBA Editor, press "Ctrl + G" and the Immediate pane will appear. The Debug.Print command is extremely (almost required in some cases) for debugging applications as you can output information, but keep it from the users view. In terms of getting the New ID number for a newly created field, it can be awkward with Access. I found the best way is to:[list][*]Open up a Recordset.[*]Add a New Record.[*]The cursor should now be at the new record, so querying the "ID" fields value will give you the new ID.[*]Assign the rest of the values to the record.[*]Close the Recordset. I hope this helps, Best Regards Rob |
ok,
but how does step 3 work? I can do the others, but don't know how to do the thirth. Do you need more info to do this or not? Thanks so far... |
Vince,
No problem, its can seem a little odd at first, heres some sample code: Code:
'Test Code for Vince_421.Best Regards, Rob |
Sorry for the late response, but I was really busy with another problem to solve...
Your thing works great, thanks very much for your help. |
No problem, your welcome Vince.
Glad I could be of help! |
| All times are GMT -4. The time now is 05:01 AM. |
Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.