INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Set Variable equal to table field

Set Variable equal to table field

(OP)
Hi,

I want to assign a variable to a value retaine in a table.  I am unsure how to do this.

sUID = "SELECT tblTransferInfo.User FROM tblTransferInfo;"
      
MsgBox "UID: " & sUID

I want the value for the Field User to display.

RE: Set Variable equal to table field

dlookup("User ","tblTransferInfo")

RE: Set Variable equal to table field

(OP)
Beauty!  Works perfect.  Thanks!

RE: Set Variable equal to table field

How about the opposite?

I'd like to set a field in the table that is the recordsource of the form i'm using so that

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

will save the field set in the vba code as well.

I've used the DAO.Database,RecordSet,and Field objects with .AddNew and .Update but I'm hoping I can do this in one line since the field is in the form's recordset table.

Thanks,

David

RE: Set Variable equal to table field

Figured it out- put the field name in brackets.

If I want to set the field Username to the variable sUsername I can do so as follows:

Dim sUsername As String
sUsername = Environ("username")  'retrievs login name
[Username] = sUsername 'example of setting field to a variable

David

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close