Results 1 to 12 of 12
  1. #1
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133

    Post What's the Problem in this code

    Hello Everyone
    this code is gives me the problem , and this code is working with me in other project


    I'm using Ms Access 2010 , and also I'm using Ms Access 2010 in other project who is working without problem and the same code
    I created this project and used this code also , its doesn't work

    Click image for larger version. 

Name:	Capture.PNG 
Views:	20 
Size:	25.7 KB 
ID:	34477

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You haven't declared the first three variables you have used ;

    Code:
    Sales_Cost
    Fisrt_Date_Of_Payment
    Number_Of_Installments
    The reason is that the local version of the database has Option Explicit in the definition of the module.
    This is a GOOD thing as it forces you to declare your variables. And would also probably have picked up on the spelling mistake.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    did you dim Sale_Cost, First_Date_of_Payment, and Number_of_Installments?

  4. #4
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    thanks a lot
    but its gives me a problem in here

    Click image for larger version. 

Name:	Capture -1.PNG 
Views:	20 
Size:	35.1 KB 
ID:	34478

  5. #5
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Correct.

    You need to declare those variables. https://msdn.microsoft.com/en-us/vba...or=-2147217396

    Code:
    Dim    Sale_Cost                      as Currency
    Dim    Fisrt_Date_Of_Payment    as Date
    Dim    Number_Of_Installments  as Integer
    I have guessed at the type of data you want to use.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Mehvan,

    Always include Option Explicit in your modules.

    When posting code, please post the entire sub or function.

  7. #7
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133

    Post

    this is part of project


    111.zip

  8. #8
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Yes and as I advised you needed to declare those variables ;
    Code:
    Private Sub CmdInstalAmount_Click()
        On Error GoTo err_CmdInstalAmount_Click
        
        Dim rst As DAO.Recordset
        
        Dim i As Integer
        
        Set rst = Me.RecordsetClone
        
        Dim Sale_cost As Currency
        Dim Fisrt_Date_of_Payment As Date
        Dim Number_Of_Installments As Integer
        
        Sale_cost = Forms![InstalmentInvoiceF]![InstalmentTotal]
        Fisrt_Date_of_Payment = Forms![InstalmentInvoiceF]![InstalDate]
        Number_Of_Installments = Forms![InstalmentInvoiceF]![InstalQy]
    
    
        For i = 1 To Number_Of_Installments
        
            rst.AddNew
            rst![Forms]![SubInstalmentF1]![SubInstalmentID] = Forms![InstalmentInvoiceF]![InstalmentInvoiceID]
            rst![Forms]![SubInstalmentF1]![Instalment] = i
            rst![Forms]![SubInstalmentF1]![InstalmentAmount] = Sale_cost / Number_Of_Installments
            rst![Forms]![SubInstalmentF1]![InstalDate] = DateAdd("m", i - 1, Fisrt_Date_of_Payment)
            rst.Update
        
        Next i
        
        rst.Close: Set rst = Nothing
        
    exit_CmdInstalAmount_Click:
        Exit Sub
        
    err_CmdInstalAmount_Click:
        MsgBox Err.Description
        Resume exit_CmdInstalAmount_Click
    End Sub
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  9. #9
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    thanks a lot
    but also gives me another problem

    Click image for larger version. 

Name:	Capture.PNG 
Views:	21 
Size:	6.1 KB 
ID:	34480

  10. #10
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    I have solved it by using command in SubForm , not in Main from

    thanks for all

  11. #11
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Glad you solved it.
    For future posts it helps to post the actual code (Use the # mark in the editor to preserve its layout), not a picture, and show use the line the error occurs on.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  12. #12
    Mehvan's Avatar
    Mehvan is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    133
    thanks a lot
    I will do it next time , I didn't know that

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

Similar Threads

  1. Replies: 12
    Last Post: 08-23-2016, 09:22 AM
  2. Code problem
    By CHEECO in forum Access
    Replies: 3
    Last Post: 04-18-2016, 08:05 PM
  3. Problem with Code
    By jackiea in forum Programming
    Replies: 1
    Last Post: 10-07-2011, 05:59 PM
  4. Code Problem
    By Jeddell in forum Programming
    Replies: 2
    Last Post: 09-29-2011, 06:31 PM
  5. Problem with Code
    By cujee75 in forum Programming
    Replies: 0
    Last Post: 03-10-2006, 02:40 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