Results 1 to 9 of 9
  1. #1
    Greg is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    44

    Variable not defined

    Click image for larger version. 
<br /><script async src=
    Name: 1.png  Views: 25  Size: 166.9 KB  ID: 42594" class="thumbnail" style="float:CONFIG" />
    Hi, after I added another form to my existing database, I am starting having problems running some vba codes as I change data in form. For example when I change or select "VAT transactions" number in combo box. Form "VAT3" is intended for entering and calculating tax. Interestingly, the "VAT2" form is practically the same but I haven had any such problems there.
    Can you tell me which variables do I need to define, why didn't I have these problems before?

    Thanks for your comments.


    Code:
    Private Sub cmbVATtr_Click()
    
    If cmbVATtr.Value = 11 Then
        Me.RestTotal.Requery
     
        NETVALUE.SetFocus
        
        NETVALUE = 0
        VATOI20 = 0
        VATOI10 = 0
        VATOI05 = 0
        ExemptDeduct = 0
        IntraEUS = 0
        IntraEUG = 0
        Export = 0
        VAT76a = 0
        NSV = 0
      
        NETVALUE = RestTotal / 1.2
        VATOI20 = NETVALUE * 0.2
        
        VATAccount = 2600
        
        Me.Recalc
     
    ElseIf cmbVATtr.Value = 12 Then
         Me.RestTotal.Requery
     
        NETVALUE.SetFocus
        
        NETVALUE = 0
        VATOI20 = 0
        VATOI10 = 0
        VATOI05 = 0
        ExemptDeduct = 0
        IntraEUS = 0
        IntraEUG = 0
        Export = 0
        VAT76a = 0
        NSV = 0
      
        NETVALUE = RestTotal / 1.1
        VATOI20 = NETVALUE * 0.1
        
        VATAccount = 1610
        
        Me.Recalc
      
      
      ElseIf cmbVATtr.Value = 13 Then
        Me.RestTotal.Requery
     
        NETVALUE.SetFocus
        
        NETVALUE = 0
        VATOI20 = 0
        VATOI10 = 0
        VATOI05 = 0
        ExemptDeduct = 0
        IntraEUS = 0
        IntraEUG = 0
        Export = 0
        VAT76a = 0
        NSV = 0
      
        NETVALUE = RestTotal / 1.1
        VATOI20 = NETVALUE * 0.1
        
        VATAccount = 2605
        
        Me.Recalc
      
     ElseIf cmbVATtr.Value = 4 Then
        Me.RestTotal.Requery
     
        NETVALUE.SetFocus
        
        NETVALUE = 0
        VatValue20 = 0
        VatValue10 = 0
        VatValue05 = 0
        VatNonded20 = 0
        VatNonded10 = 0
        VatNonded05 = 0
        NetValue00 = 0
        NSV = 0
      
        NETVALUE = RestTotal / 1.2
        VatNonded20 = NETVALUE * 0.2
       
      
      
      ElseIf cmbVATtr.Value = 5 Then
        Me.RestTotal.Requery
      
        NETVALUE.SetFocus
        
        NETVALUE = 0
        VatValue20 = 0
        VatValue10 = 0
        VatValue05 = 0
        VatNonded20 = 0
        VatNonded10 = 0
        VatNonded05 = 0
        NetValue00 = 0
        NSV = 0
      
        NETVALUE = RestTotal / 1.1
        VatNonded10 = NETVALUE * 0.1
      
    ElseIf cmbVATtr.Value = 6 Then
        Me.RestTotal.Requery
    
    
        NETVALUE.SetFocus
        
        NETVALUE = 0
        VatValue20 = 0
        VatValue10 = 0
        VatValue05 = 0
        VatNonded20 = 0
        VatNonded10 = 0
        VatNonded05 = 0
        NetValue00 = 0
        NSV = 0
      
        NETVALUE = RestTotal / 1.05
        VatNonded05 = NETVALUE * 0.05
      
    ElseIf cmbVATtr.Value = 9 Then
        Me.RestTotal.Requery
    
    
        NETVALUE.SetFocus
        
        NETVALUE = 0
        VatValue20 = 0
        VatValue10 = 0
        VatValue05 = 0
        VatNonded20 = 0
        VatNonded10 = 0
        VatNonded05 = 0
        NetValue00 = 0
        NSV = 0
      
        NSV = RestTotal
      
     
    End If
    End Sub
    Attached Files Attached Files

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    You need to add Export field to qryVAT which you are using as the Record source for the form VAT3

    BTW you have an extra "End Sub" in the sub TEST_Click in form VAT2
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Put all yor variables in the DIM line.

  4. #4
    Greg is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    44
    Since I put this statment in code: Dim NETVALUE, VATOI20, VATOI10, VATOI05, ExemptDeduct, IntraEUS, IntraEUG, Export, VAT76a, NSV As Double
    I get Run time error 424 Object required.

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    But they aren't variables 🤔.
    Works fine if you follow the advice I gave in my last post. I tested it.

  6. #6
    Greg is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    44
    If I add "Export" field to qryVAT what should I do then?

  7. #7
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Nothing. That's all that is required.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  8. #8
    Greg is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    44
    Thanks it works. Some fields were missing in VAT3 form.

  9. #9
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Greg View Post
    Thanks it works. Some fields were missing in VAT3 form.
    Being a little nit-picky, Forms do not have FIELDS; Forms have CONTROLS.
    Controls can be unbound or bound to fields in the form record source.

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

Similar Threads

  1. Object variable or With block variable not defined
    By PorscheMan in forum Programming
    Replies: 3
    Last Post: 01-16-2013, 01:53 PM
  2. Compile error: Variable not defined
    By HarryScofs in forum Access
    Replies: 8
    Last Post: 07-25-2011, 09:06 AM
  3. DSum criteria using a variable that has been defined
    By beanhead0321 in forum Programming
    Replies: 5
    Last Post: 07-24-2011, 09:57 PM
  4. MakeTable Query with Variable user defined Name
    By Dinzdale40 in forum Programming
    Replies: 1
    Last Post: 03-09-2011, 11:26 AM
  5. Replies: 23
    Last Post: 03-26-2009, 06:50 PM

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