Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting current autonumber id in a variable

Status
Not open for further replies.

medium

MIS
Aug 28, 2002
30
US
I am currently trying to get a new record's id number assigned to a variable. I'm not too sure how to proceed. I've tried a recordset approach. However, that didn't seem to work. Moreover, I've tried getting the current record number but the actual record number is different from the Autnumber ID number.

I'm trying to do the above for a Work Order form. The form has two fields on it among others entitled "Machine Number" and "Machine Description." I'm trying to fill in the Machine Description by assigning the Machine Number that is selected to a variable and then using that variable to do a "find" in a recordset for that machine and then its corresponding description. Before I can do that however, I have to be able to find the record for the Work Order record which contains the Machine Number. Perhaps it is possible to pass the selected number straight to a variable, but I've not been able to find any code to do this.

I've tried the Me!. However I keep getting an error message that says that I am using it incorrectly. What's funny here is that I typed it in exactly the way the example says in the help file and still got the same error message.

Perhaps I am going about this the wrong way. Any comments would be much appreciated.

Thanks
 
Are you saving the record before performing your seach? And is it possible to create a table of machines with the Machine ID and Description as fields, that you can use to find the information that you want?
 
No, I'm not saving it before. I have played around with rstrecordsetname.update before doing the search. However, that didn't produce the desired result. The problem I have at that point though is getting the autonumber into a variable. My lack of success may have something to do with not saving the record first or at least not saving it correctly.

As far as the table, yes I do have a separate table with the Machine number and machine description in the same table. This is the table I am opening up with a recordset and the table in which I search for the machine number.

Thanks for your post.
 
If you save the record first, you should be able to get the number by using the "!" operator rather than the "." operator:

Me![Autonumber Field] vs Me.[Autonumber Control]

Also, since the tables are seperated, you can base the form on a query that defines the relationship between the two fields. Pull all of the fields from one table, and the description field from the machine table. Then, when the machine ID field changes in the one table, the description field will update automatically to the description from the other table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top