Results 1 to 7 of 7
  1. #1
    merciers is offline Novice
    Windows 10 Access 2002
    Join Date
    Apr 2022
    Posts
    5

    Put a value in the fiels of a new regord on an opening form

    Hi
    An Access VBA newbie question

    I have
    • a plublic variable Pub_Numero_Client
    • a btn opening a form via the vba command DoCmd.OpenForm sDocName, acNormal, , , acFormAdd

    My issue is to put Pub_Numero_Client in the field id_client of the new created record

    Probably trivial but I have been trying a lot of things without any success


    Can you help me ?

    Regards

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You could try in the Current Event or Before Insert of the form (depending on whether you want to see it or not)
    Code:
    If Me.NewRecord then
        Me.ID_Client = Pub_Numero_Client
    End If
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Because you open the new form in data add mode you can use the default value property of the ID_client textbox. Open the form in design view, click on the ID textbox and in the Default Value property (on the Data tab of the Properties window) enter =fnNumero_Client

    Finally just add this public function to a standard module:
    Code:
    Public Function fnNumero_Client() as Long
       fnNumero_Client=Pub_Numero_Client
    End Function
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    merciers is offline Novice
    Windows 10 Access 2002
    Join Date
    Apr 2022
    Posts
    5
    Hello Welshgasman and Vlad

    Thank you for your replies.
    I had tried them and it did not work and so I was wondering it did not work because the record was not really created and so I had tried to play with the events Load or activation of the formula.

    But with your replies telling me I was in the good direction ,I just realize ( at last ) that my issue is that the field id-client is considered at a list control in my formula.
    I will try to modify that and will tell if I am successful.

    Anyway thank you for your help

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Can you please show us what you mean by
    is considered at a list control in my formula
    ? Maybe you can upload a small db sample with just the form(s) and tables involved so we could have a look.

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

  6. #6
    merciers is offline Novice
    Windows 10 Access 2002
    Join Date
    Apr 2022
    Posts
    5
    Hello Welshgasman and Vlad

    Sorry Vlad I was not very clear and precize but I won !!! With your help I have been able to fixt it. It works well now.


    Thanks a lot to you both

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 8
    Last Post: 03-20-2017, 07:22 PM
  2. Replies: 2
    Last Post: 11-22-2015, 07:24 PM
  3. Replies: 5
    Last Post: 01-24-2015, 12:59 AM
  4. Replies: 3
    Last Post: 04-10-2012, 02:36 PM
  5. Replies: 2
    Last Post: 04-08-2012, 03:04 PM

Tags for this Thread

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