Page 1 of 3 123 LastLast
Results 1 to 15 of 34
  1. #1
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    21

    Help needed with passing values between forms using OpenArgs

    Hi

    I am very new to VBA and trying to work out how to pass information between forms using OpenArgs (after finding this online).

    I have two forms: 'Record time 2' and 'Add new client'

    I want to have 'Record time 2' load from the 'Add new client' form on a click button. When that happens I want 'Client name' in 'Add new client' to transfer over to 'Record time 2'.

    I've got this far and here is what is in the code so far - the form opens but nothing transfers across right now:


    Option Compare Database


    Private Sub Form_Load()


    Dim i As Integer
    i = CInt(Me.OpenArgs)


    End Sub




    Private Sub Record_time_button_Click()


    DoCmd.OpenForm "Record time 2", acNormal, , , acFormAdd, acWindowNormal, "Client name"


    End Sub

    Any help would be greatly appreciated - with much tahnks from me

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    1,603
    Please try something like this (you should avoid using spaces in the field and object names):
    Code:
    'Add new client form
    Private Sub Record_time_button_Click()
    DoCmd.OpenForm "Record time 2", acNormal, , , acFormAdd, acWindowNormal, Me.txtClientName ' txtClientName is the name of the textbox control on the Add New Client form "Client name"
    End Sub
    'Record time 2 form
    Private Sub Form_Open(Cancel As Integer) 
    Me.ClientName=me.OpenArgs     'Me.ClientName refers to the textbox control on this form that is supposed to get the client name
    'You could also simply try to reference the control directly
    'Me.ClientName=Forms![Add New Client]![txtClientName]
    End Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    21
    thanks so much Gicu! It won't work (button on Add new client form) and is stopping at me.txtClientName? Any idea why? Tried to send you a print screen but won't allow it.

    Client name field isn't a primary key if that might be the problem? Also it is a compiled field. It is made up of first name and last name....in case that's a problem?

    It is doing the same thing on the 'Record time 2' form.

  4. #4
    Welshgasman is offline Novice
    Windows 10 Access 2007
    Join Date
    Jan 2017
    Posts
    28
    What you were given has to be amended for your control name for ClientName?

    Likely it is not called txtClientName in this case? if you have spaces in your control names (not advised) then ou also need to surround the control name with []

    Also would help if you reported what error was being shown.?

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    1,603
    You need to change the code to match your forms:
    Code:
    'Add new client form
    Private Sub Record_time_button_Click()
    DoCmd.OpenForm "Record time 2", acNormal, , , acFormAdd, acWindowNormal, Me.txtClientName ' txtClientName is the name of the textbox control on the Add New Client form "Client name"
    End Sub
    'Record time 2 form
    Private Sub Form_Open(Cancel As Integer) 
    Me.ClientName=me.OpenArgs     'Me.ClientName refers to the textbox control on this form that is supposed to get the client name
    'You could also simply try to reference the control directly
    'Me.ClientName=Forms![Add New Client]![txtClientName]
    End Sub
    Being a primary key and a calculated value should not matter if you put in the right names.

    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    8,953
    It seems to me that you have design issues. You should be passing the customer ID PK value (Long Integer) instead of the text First & Last names.

    There are easier ways to create records in an hours table that having to use pop up forms to enter data......
    HTH
    -----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  7. #7
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    591
    Client name field isn't a primary key if that might be the problem? Also it is a compiled field. It is made up of first name and last name....in case that's a problem?
    Its a huge problem if you have 2 clients with the same name!
    You should have a table of clients which contains a primary key and all the unique info for that client. Thereafter you use that primary key to reference that client in any other tables.

  8. #8
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    591
    One other observation . . .

    You posted
    Code:
    Option Compare Database
    
    
    Private Sub Form_Load()
    
    
    Dim i As Integer
    i = CInt(Me.OpenArgs)
    
    
    End Sub
    You should declare Option Explicit in all your modules
    Code:
    Option Compare Database
    Option Explicit

  9. #9
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    21

    thanks, now a new error

    Quote Originally Posted by Welshgasman View Post
    What you were given has to be amended for your control name for ClientName?

    Likely it is not called txtClientName in this case? if you have spaces in your control names (not advised) then ou also need to surround the control name with []

    Also would help if you reported what error was being shown.?
    That makes complete sense Welshgasman! Complete VBA NAFF here lol. Have pulled together a db for work, not my skill set lol. Just need to sort a couple of more complex things for this Access newbie and I'll be done thank goodness.

    So I amended the name and learned about having to use brackets with spaces (thanks heaps!) but now I get runtime error 2448 - you can't assign a value to this object when I click on the button. When I click on 'debug' it takes me to the 'Form' 'Open' property and highlights this bit: Me.[Client name] = Me.OpenArgs. Any ideas what is going wrong?
    Thanks a ton for your help!

    Kellie

  10. #10
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    21
    thanks so much for the clarification, arrrggghhh it's all like double dutch to me! lol

  11. #11
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    21
    Thanks so much for your reply - I'm sure I have multiple design issues ssanfu! lol. Yes I do use client id (primary key). Would love to hear about an easier way to record hours worked than staff having to click on a box and put hours in. I'm all ears.... just make it basic for this absolute newbie!

  12. #12
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    21
    thanks moke123. I do have a Client ID table as primary key thankfully. A name obviously means more to staff than an ID hence why I am using the compiled client name throughout the database, but it links to their CLient ID

  13. #13
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    21
    thanks so much for that tip! really appreciate the help

  14. #14
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    591
    You should be passing the ClientID not the client name. If your passing text it probably needs to be delimited.

    It would probably be helpful for you to post a copy of you db with any confidential info redacted.

    I'm with Steve. You probably have a design issue.

    edit:
    A name obviously means more to staff than an ID hence why I am using the compiled client name throughout the database, but it links to their CLient ID
    you can still display a name when using a primary key on a record.

  15. #15
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    21
    yes, thanks, that one I worked out for myself! amazingly lol

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. passing values between forms
    By CurtisC in forum Access
    Replies: 2
    Last Post: 04-13-2020, 08:55 AM
  2. Replies: 14
    Last Post: 05-26-2015, 04:30 AM
  3. passing values between forms
    By paulw in forum Access
    Replies: 4
    Last Post: 06-15-2011, 08:52 AM
  4. PASSING Values between Forms
    By chhinckley in forum Programming
    Replies: 1
    Last Post: 08-27-2010, 10:19 AM
  5. Replies: 3
    Last Post: 06-02-2009, 09:51 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 - Senior Forums