Share via

Assigning Tempvar

Anonymous
2019-01-01T21:56:48+00:00

I wish to assign a Table's Record ID to Tempvar to use it in other parts of my application.

Using the SetTempVar  macro, I tried assigning the tbl_Tablename.ID  to the variable name, but Access 2010 will not accept it.

SetTempVar will accept static data (e.g. a number), but I can't seem to get it to accept the record ID from the table.

I am surely not the first to stumble onto this, but can't seem to find the appropriate help anywhere I've looked.

Can someone point me to an article or example?

Thanks

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2019-01-03T21:04:44+00:00

    Merci Daniel. I'll try our suggestion.

    Dave

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2019-01-03T21:03:02+00:00

    Hi Tom. Thanks for your swift reply. Your response makes perfect sense - the ID in the table is numeric - Auto-assigned as advised by Access. I tried to assign TempVar using the macro SetTempVar using the table name in the expression after I used another macro to get to the last record.

    It looks like this SetTempVar

                                     {Name}  LastrcdID

                                     {Expression}  =[tbl_Mytable]![ID]

    The response when I step through is that it doesn't recognize MyTable in the expression. It doesn't make sense to me either. If I assign a number in the expression, it accepts it, as you suggested it should. 

    I like the simplicity of your suggestion, assigning it in VBA, but I have shied away from getting into VBA since Macros have served me very well so far. Guess it's time for me to roll up the sleeves!

    Thanks for your help.

    Dave

    Was this answer helpful?

    0 comments No comments
  3. Tom van Stiphout 40,201 Reputation points MVP Volunteer Moderator
    2019-01-02T00:48:40+00:00

    > SetTempVar will accept static data (e.g. a number), but I can't seem to get it to accept the record ID from the table.

    I don't get it. Isn't the ID value in your table static data, most likely numeric?

    I don't use macros, but this one-liner in VBA would do it:

    Tempvars("myTempvar") = Me.ID

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2019-01-01T23:34:48+00:00

    Are you not doing this through your form?  So, should you not be signing it the form and control name?

    Just to further the concept.

    SetTempVar

    Name           YourTempVarName

    Expression   =[ID]

    But I also agree with Tom, don't use Macros, they had their reason for web apps, but now that those are dead use VBA.  It is much more powerful and easier to work with and then you only have one place to search.

    Was this answer helpful?

    0 comments No comments