Results 1 to 4 of 4
  1. #1
    ManvinderKaur is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    10

    calling function

    Hi I have a sub and a function..
    I call function Validate Data my code calling function do not run even if validateData is true....
    How to fix this ..I think i am calling funtion in wrong way
    Code:
    Private Sub cmdTransferData_Click()
    On Error GoTo Err_cmdTransferData_Click
    Dim dblLongDecimal As Double ' Longitudinal Decimal
    Dim dblLatDecimal As Double  ' La
    ****
    'call for funtion Validate data for data validation
            If ValidateData = False Then
            Exit Sub
            End If
            
    *******
    End Sub
    'Purpose: Data validation while importing data from lHeritage.xls
    Private Function ValidateData() As Boolean
    Dim strMessage As String
    Dim Validate As Boolean
    Dim dbISD As DAO.Database
    Dim rsqryImportDifferenceCount As DAO.Recordset
    Dim qdfqryImportDifferenceCount As QueryDef
    Dim DataValidationMessage As VbMsgBoxResult
    Validate = True  ' initialise with True value
    strMessage = "Import Failed: The following coloumns in CulturalHeritage.xls has failed data validation."
    Set dbISD = CurrentDb()
    Set qdfqryImportDifferenceCount = dbISD.CreateQueryDef("")
    qdfqryImportDifferenceCount.SQL = "SELECT * from qryImportDifferenceCount"
    Set rsqryImportDifferenceCount = qdfqryImportDifferenceCount.OpenRecordset()
    'Data Validation check for Map Name
    If rsqryImportDifferenceCount!MapName <> 0 Then
    strMessage = strMessage & vbCrLf & "MapName"
    Validate = False
    End If
    'Data Validation check for LGA
    If rsqryImportDifferenceCount!LGA <> 0 Then
    strMessage = strMessage & vbCrLf & "LGA"
    Validate = False
    End If
     
    If Validate = False Then
    ValidateData = False
    DataValidationMessage = MsgBox(strMessage & vbCrLf & "Please make sure you have added data into database before" & _
    " adding a new entry in Dropdown list for CulturalHeritage.xls coloumns", vbInformation + vbOKOnly, "Data Missmatch")
    End If
    'close record set
    rsqryImportDifferenceCount.Close
    End Function


  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    I'm not clear on what is going wrong. You're calling the function correctly (though I would make it a Public function). Unless I'm blind, I don't see any way the function can return true. The only line that ever sets ValidateData sets it to False. I would expect it to be set to True under the applicable circumstances, or perhaps simply being set to the value of Validate, since that appears to be set both ways.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ManvinderKaur is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    I have introduced this..now working fine....
    Code:
    If Validate = False Then
    ValidateData = False
    DataValidationMessage = MsgBox(strMessage & vbCrLf & "Please make sure you have added data into database before" & _
    " adding a new entry in Dropdown list for CulturalHeritage.xls coloumns", vbInformation + vbOKOnly, "Data Missmatch")
    Else
    ValidateData = True
    End If
    'close record set
    rsqryImportDifferenceCount.Close
    End Function

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Syntax Error while calling sub: Expected: =
    By cowboy in forum Programming
    Replies: 3
    Last Post: 07-12-2010, 02:21 PM
  2. Replies: 4
    Last Post: 03-31-2010, 03:41 PM
  3. Calling Query from different Access DB
    By Jerry8989 in forum Queries
    Replies: 4
    Last Post: 10-02-2009, 08:48 AM
  4. Replies: 0
    Last Post: 10-04-2008, 07:23 AM
  5. Calling a function and returning a value
    By 3dmgirl in forum Programming
    Replies: 0
    Last Post: 04-23-2007, 02:20 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