Results 1 to 12 of 12
  1. #1
    kmw is offline Novice
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    27

    Updating records using visual basic

    My textbox Text24 remains blank. My update query is linked to my table by a Where statement that is based on text 24. However text 24 remains blank. I have tried making ID my PK and I have changed it to not being a PK and it still remains blnk.



    Private Sub CommandUpdatePatient_Click()

    DoCmd.OpenForm "FormUpdatePatient"

    [Forms]![FormUpdatePatient]![Text24] = DLookup("[ID]", "DISCHARGE_DELAY", "[ID] = [Forms]![FormListBoxSearch]![Combo65]")

    End Sub

  2. #2
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    <EDIT> ohh wait now i see what ur trying to do. Your trying to get the value from another form.
    Then my code below wont work either i think.
    I have struggled with this a while ago. And what i did was pass the value to the other form using open arguments.
    I will look that up for u.
    Disregard the code below

    Try this in the form_current section :

    me.Text24 = Dlookup ("ID", "DISCHARGE_DELAY", "ID = Combo65")

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Please show the sql for
    My update query is linked to my table by a Where statement that is based on text 24.
    You could try ( not tested)

    [Forms]![FormUpdatePatient]![Text24] = DLookup("[ID]", "DISCHARGE_DELAY", "[ID] = " & [Forms]![FormListBoxSearch]![Combo65] )

  4. #4
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Ok i looked it up for you.

    DoCmd.OpenForm "FormUpdatePatient", , , , , , Me.ID.Value

    This will copy the value of ID field (or any other field of your choosing) into the memory.

    Then "paste" it into the new form by using form_load()

    Private Sub form_load()
    If Me.OpenArgs <> vbNullString Then Me.ID = Me.OpenArgs
    End Sub

    This way you pass the ID value from one form to another.

    Hope it helps

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I agree with JeroenMioch with Openargs -if opening the Form is the issue. I didn't pick up on your opening the form in the post, maiinly because of the title Updating records ....

  6. #6
    kmw is offline Novice
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    27
    I think there may be a different problem. I have changed what I am doing and I am trying to put a text box with the ID in the same form as the combo box. The form displays all the values of my combo box except for the ID. The ID is no longer a PK.

    Text63 is the where ID should be. All of the other text boxes work except for text63. Text63 will also display other values other than ID.

    Thank you so much for your help!!!!

    Private Sub Combo65_Change()

    Me.Text63 = Me.Combo65.Column(13)
    Me.Text23 = Me.Combo65.Column(1)
    Me.Text25 = Me.Combo65.Column(2)
    Me.Text27 = Me.Combo65.Column(3)
    Me.Text29 = Me.Combo65.Column(4)
    Me.Text32 = Me.Combo65.Column(5)
    Me.Text34 = Me.Combo65.Column(6)
    Me.Text36 = Me.Combo65.Column(7)
    Me.Text38 = Me.Combo65.Column(8)
    Me.Text40 = Me.Combo65.Column(9)
    Me.Text42 = Me.Combo65.Column(10)
    Me.Text44 = Me.Combo65.Column(12)
    Me.Text55 = Me.Combo65.Column(11)

    End Sub







    Quote Originally Posted by JeroenMioch View Post
    Ok i looked it up for you.

    DoCmd.OpenForm "FormUpdatePatient", , , , , , Me.ID.Value

    This will copy the value of ID field (or any other field of your choosing) into the memory.

    Then "paste" it into the new form by using form_load()

    Private Sub form_load()
    If Me.OpenArgs <> vbNullString Then Me.ID = Me.OpenArgs
    End Sub

    This way you pass the ID value from one form to another.

    Hope it helps

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I don't think we understand what exactly you are trying to do.
    Can you briefly describe the application and what exactly you want to happen (plain English please).

    How does the title Updating records using vb(a) relate to the various forms involved?
    Could you describe each form as to the purpose and the order things are happening?

  8. #8
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    I agree with Orange that were not quit sure what your trying to accomplish

    Also, i would advice you to name your Fields, comboboxes, labels in such a way that you can allways see what kind of object it is, and more or less what it does.

    So if i were to name a button that makes a report about patients i would name it "btnMakeReportPatients"
    Or a field holding the ID of a record "fldID"
    and so on...

  9. #9
    kmw is offline Novice
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    27
    I have one form to search for information using a combobox and then there is a button on that form to edit that information. The button opens up a form with the existing information to be edited, but the edits do not save. My query to save the edits is based on a text box displaying the ID but I can't get any of my text boxes to display the ID

  10. #10
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Well as i stated try the openargs method. It is a good way to pass the ID value from one form to another.

    Try it and get back to us with the results

  11. #11
    kmw is offline Novice
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    27
    When I pasted:

    Private Sub CommandUpdatePatient_Click()

    Me.Text24 = DLookup("ID", "DISCHARGE_DELAY", "ID = Combo65")

    DoCmd.OpenForm "FormUpdatePatient"

    End Sub

    Into the Event Procedure of my button that brings you to the UpdateForm, I received an error because Text24 is on the UpdateForm. Am I adding that argument to the wrong Event Procedure?

  12. #12
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    The ID you want to "bring with u" is in your form FormListBoxSearch right ?
    In my example the field on this form it self is called "ID" as is the "ID" field on the new form.

    When opening your form FormUpdatePatient you need to copy that ID number by opening the form in this way :

    DoCmd.OpenForm "FormUpdatePatient", , , , , , Me.ID.Value

    Next you go to that form (FormUpdatePatient) and go to visual basic. Select the Form_load() event of that form and put this code in it:

    If Me.OpenArgs <> vbNullString Then Me.ID = Me.OpenArgs

    So, when the OpenArgs holds a value he will paste it in the ID field of the new form.

    I hope your with me now

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Visual Basic
    By kwooten in forum Queries
    Replies: 2
    Last Post: 01-25-2012, 08:22 AM
  2. problem in editing records with visual basic
    By davidvhp in forum Programming
    Replies: 31
    Last Post: 12-05-2011, 07:36 PM
  3. how to use visual basic in access
    By learning_graccess in forum Access
    Replies: 3
    Last Post: 12-05-2011, 03:23 PM
  4. trying to learn visual basic
    By darklite in forum Programming
    Replies: 7
    Last Post: 08-24-2011, 02:18 PM
  5. Can't see visual basic code
    By Michele Keck in forum Forms
    Replies: 5
    Last Post: 09-29-2010, 11:31 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