Page 2 of 2 FirstFirst 12
Results 16 to 26 of 26
  1. #16
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    umm..what I meant to ask is. I am not sure how to convert this macro code:



    SetTempVar
    Name ActiveControlValue
    Expression = [Screen].[ActiveControl]


    SearchForRecord
    Object Type
    Object Name
    Record First
    where condition =="[lngID]=" & [TempVars]![ActiveControlValue]


    to vb code! The syntax is not the same for both. This is the code I used in vb to convert the macro (wrote the code manually as access doesn't support macro to code conversion):


    Private Sub cmbEditUser_AfterUpdate()
    Me.txtUserName = Me.cmbEditUser.Column(1)
    TempVars("ActiveControlValue") = Screen.ActiveControl
    DoCmd.SearchForRecord , "", "", "[lngEmpID] = " & "[TempVars]![ActiveControlValue]"
    End Sub

    But I am getting an error stating "Tempvars can only store data. They cannot store objects"

  2. #17
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I don't know what the TempVars structure is for nor why you need to do the Search. What are you trying to do?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #18
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    I have another hidden textbox called 'lngEmpID' and based on the value in the textbox, I have written a query. Like, update field set field.value = "blah" where empId = lngEmpID. So I need the value in lngEmpID also to be automatically generated based on comboBox values. But when I use the code
    Me.lngEmpID = Me.combobox.Column(1)
    for the lngEmpID field, I get the error "Run time error: You can't assign a value to this object"

    But the macro helped in automatically updating the lngEmpID field. So I wanted to convert that to vb code.

  4. #19
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    First of all should be Me.lngEmpID = Me.cmbEditUser (no column reference needed and Column(1) gets the name, not ID - index starts with 0). Not sure why can't update the hidden textbox. Is it unbound? Is there an expression in ControlSource?

    Second, the ID is available in the combobox, why the hidden textbox?

    Third, you want to update a value in another table? Why? What value?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #20
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    The ID is not available in the combo box, Only the name is available. Like if the name "Jessica" has the Id "10", then the name "Jessica" is displayed in the comboBox and "10" is displayed in the hidden textbox.

    So, basically what happens is, based on what the user selects in teh comboBox, the hidden textbox ID gets updated and also the userName textbox gets updated (this is currently working now). User can change the value in the userName textbox and click an update button. The update button has the query I mentioned above. I want the code to update values based on userID, because the comboBox has only a name and 2 (or more) users can share the same name.

    Hope I am being clear!

  6. #21
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    The combobox does have the ID. It is in the RowSource SQL statement. It is just that the ID column is hidden because of the 0 width. But can still get the ID value from combobox. The BoundColumn is the actual value of the combobox, regardless of the display. Because first column is the ID and is also the BoundColumn and it is the ID that desired, Column(0) reference not needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #22
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    err, I am sorry, but I didn't understand that. Should I use column(0) to get the user name?

    so my query would be:

    update field set field.value = "blah" where empId = "Me.combobox.Column(0)"

  8. #23
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Column indexing begins with 0.

    The RowSource SQL returns fields in this order: lngID, strEmpName

    Column(0) gets lngID
    Column(1) gets strEmpName

    I still don't understand why you want to do this update.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #24
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    yayy! It works! Just one quick question, what do I do to display column(0). I mean, when I click on the comboBox, I should see, empID|empName. I know I gotta set something in properties, but not sure what.

    thanks a ton btw!

  10. #25
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    ColumnWidths property

    If you want to show the ID then change value from 0 to whatever.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #26
    accessnewb is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Location
    New York, NY
    Posts
    116
    Works!! thanks again! Am gonna mark this as solved :-)

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 08-13-2011, 04:44 AM
  2. Replies: 12
    Last Post: 06-16-2011, 01:35 PM
  3. how to edit listboxes?
    By RedGoneWILD in forum Programming
    Replies: 2
    Last Post: 08-23-2010, 11:53 AM
  4. Replies: 8
    Last Post: 06-30-2010, 10:57 PM
  5. Cannot not edit form
    By stingray_69 in forum Forms
    Replies: 3
    Last Post: 03-18-2010, 10:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums