Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 33
  1. #16
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    20
    So this is where I am stuck now, any help would be greatly appreciated



    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?

  2. #17
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    8,942
    Maybe you would post your dB with any sensitive data changed/ removed???
    HTH
    -----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  3. #18
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    588
    is [Client name] a calculated field? I dont think you can assign a value to a calculated field.
    Me.[Client name] = Me.OpenArgs wont work and is another reason you should be passing a PKey.

  4. #19
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    20
    thanks moke123, I tried changing the field to the primary key Client ID and get the exact same error - it stops at the 'Form "Open" property highlighting the Me.[Client ID] = Me.Open Args line of code.

  5. #20
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    20
    Hi Ssanfu

    Sure can but it is split into fe and be, so will it work if I just post the fe?

  6. #21
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    20
    Hey all - it must be some simple error I am making because Access knows the name of the client on the screen. It just won't transfer it?

    I can't paste it due to client privacy but when I hover over the last part of the code Me.OpenArgs (in 'Form', Open') I can see the client's name that's on the screen.

    Option Compare Database
    Option Explicit

    Private Sub Detail_Click()

    End Sub

    Private Sub Form_Open(Cancel As Integer)
    Me.[Client name] = Me.OpenArgs

    End Sub

  7. #22
    virgilio is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    66
    Quote Originally Posted by kelliejean View Post

    Private Sub Form_Open(Cancel As Integer)
    Me.[Client name] = Me.OpenArgs

    End Sub
    The way this last bit is written it looks like you have some things backwards.

    Is this bit of code: A). on the form that’s opening a new form OR B). the form that’s newly opened?

    When you say you can mouse-over and see the clients name, are you mousing over A.) “me. [Client Name]” or B).“me.OpenArgs”?

    If your answer is A) and A), then switch that line to read:

    Code:
       OpenArgs = Me.[Client name]

  8. #23
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    20
    thanks virgilio The error starts when I click the button on form A but when I hit on the 'debug' it takes me to the 'Form' 'Open' property that is set on form B. The line is highlighted as an error but when I hover over the = Me.OpenArgs in that string it shows the name of the client that I have in front of me in form A. If I try to open Form B direct I get the 2448 error 'you can't assign a value to this object' straight up. SO it looks like the error is attributed to form B.

  9. #24
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    588
    First, when you say "form open property" do you mean the Form Open Event?
    as in
    Code:
    Private Sub Form_Open(Cancel As Integer)
    
    End Sub
    You said that [Client Name] is a compiled field which I assume is a calculated field which you get from concatenating First Name and Last Name.
    You can not set the value of a calculated field in the manor you are attempting. You would need to set the first name and the last name in your table because access is doing the calculation to make it [Client Name].
    You cannot set the value of a calculated field with code. That is why you are getting that error.

    2448 error 'you can't assign a value to this object'
    The object is your calculated field and you cannot assign a value to it.

  10. #25
    virgilio is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2019
    Posts
    66
    It looks like you want to write 'Client Name' into the table that the new form is based on, right?

    If yes, then you can definitely do this with raw SQL. The way it works is you write a command in SQL language, in quotation marks so that its a string, and then tell Access to use its SQL interpreter (DoCmd.RunSQL) to write into the database. I use the same technique in Python and Javascript if I am not using a library's methods to interface with a database.

    Here's the code:

    1. Write your SQL string:

    Code:
    Dim StrSql As String
    
    StrSql = " INSERT INTO YOUR_TABLE_NAME ( THE_FIELD_YOU_WANT_TO_UPDATE ) VALUES ('YOUR_NEW_VALUE' );"
    DoCmd.RunSQL StrSql
    2. This is where it gets confusing:

    The quotation marks around 'YOUR_NEW_VALUE' are important. But the value that you want to pass is in a variable, so you need to break out of the quotes to use that variable, so the SQL string becomes:

    Code:
    Dim StrSql As String
    
    StrSql = " INSERT INTO YOUR_TABLE_NAME ( THE_FIELD_YOU_WANT_TO_UPDATE ) VALUES (' " & me.OpenArgs & " ' );"
    DoCmd.RunSQL StrSql
    Its cumbersome but reliable. You can substitute in a variable for YOUR_TABLE_NAME and THE_FIELD_YOU_WANT_TO_UPDATE in the same way, but you have to make sure that your quotation marks are exactly right. There are a lot of other SQL commands you can use instead of "INSERT INTO", like "SELECT", "UPDATE", or "CREATE DATABASE", but those are structured differently and you'll need to read up on them.

    Also using all capital letters is usually just a convention that some people use for SQL, but I'm not sure that its necessary in Access. I would suggest using all capitals at first to make sure it works before you experiment around with lower case.

  11. #26
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    588
    See the attached.

    Is this what your trying to accomplish?
    Attached Files Attached Files

  12. #27
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    8,942
    @kelliejean, You can make a copy of the FE & BE, delete the data and add a couple of records using names like Daffy Duck, Mighty Mouse, Clark Kent, etc.
    Then do a Compact and Repair", then compress the two files - either one zip or two zip files - then post here.
    HTH
    -----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  13. #28
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    20
    It works moke123 . Wow, that was so much help! Thank you thank you thank you ! Just being able to see how you used all the coding to get it to work was super helpful! Woo hoo. I got it to work but not exactly as you have it there - the Client ID came across not the client name like yours did which is all good.....I actually got it to work with Client name by replaceing Client ID but actually I would really like to see client name and client ID come across..... if you might be so generous to show me the added code that I can use to have both come across I would be extremely grateful for your time!

  14. #29
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    20
    thanks so much virgilio! I might give this a try at some point - it seems practical - I'm just not sure where you would put the code? Form, click button.......gawd, being a newbie to this stuff is panful! LOL.

  15. #30
    kelliejean is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    20
    thanks for letting me now ssanfu!

Page 2 of 3 FirstFirst 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