Results 1 to 4 of 4
  1. #1
    masoud_sedighy is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Dec 2011
    Posts
    78

    “#Error” in related field before entering data in main field

    Hello



    In my query I have used built in function and parameter of this function is another field of my query.


    Now in my form before entering anything in textbox1, textbox2 shows “#Error”, when I finish entering and left textbox1 and set focus on textbox2 my function operates and results is ok.

    How I can solve problem of “#Error” in related field.

    Best regards.

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by masoud_sedighy View Post
    Hello

    In my query I have used built in function and parameter of this function is another field of my query.


    Now in my form before entering anything in textbox1, textbox2 shows “#Error”, when I finish entering and left textbox1 and set focus on textbox2 my function operates and results is ok.

    How I can solve problem of “#Error” in related field.

    Best regards.
    You didn't post the SQL of the query, say what function or the parameter values so it is hard to be specific. One thought would be to use the IIF() function to check that a parameter is not NULL or zero. Another would be to use the NZ() function on each parameter to change a NULL to a different value.

  3. #3
    masoud_sedighy is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Dec 2011
    Posts
    78
    Hello

    My sql query is like below and
    My main field is:[Due Date]
    Related field: Farsi_Due_Date

    And my function is M2SDATE (Date Parameter)

    I have used “M2SDate (Tasks_Recieved![Due Date]) AS Farsi_Due_Date” in the query.

    Now in the form when I want to start data entry “Farsi_Due_Date” shows “#error” until I entered data in [Due Date] and get focus on another field “#error” will be removed.


    sql:

    SELECT Tasks_Recieved.ID_Recieved, Tasks_Recieved.Sender, Tasks_Recieved.ID__RecievedDate, Tasks_Recieved.Documentcode, Tasks_Recieved.Title, Tasks_Recieved.DocumentDate, Tasks_Recieved.Priority, Tasks_Recieved.Status, Tasks_Recieved.[% Complete], Tasks_Recieved.[Assigned To], Tasks_Recieved.Description, Tasks_Recieved.[Due Date], M2SDate(Tasks_Recieved![Due Date]) AS Farsi_Due_Date, Tasks_Recieved.Attachments, Tasks_Recieved.ID_Send
    FROM Tasks_Recieved;


    My module:
    Public Function M2SDate(DocumentDate As Date)


    Dim ifday, ifmonth, ifYear, ifdayOfyear As Long
    Dim iyear, idayOfyear As Long
    Dim iNumDayOfyear As Long
    Dim aifMonthDays



    aifMonthDays = Array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29)
    iNumDayOfyear = 365
    Debug.Print DocumentDate
    iyear = Year(DocumentDate)

    idayOfyear = DatePart("Y", DocumentDate)
    If isly(iyear - 1) Then
    iNumDayOfyear = 366
    aifMonthDays(11) = 30
    End If

    If (idayOfyear > 79) Then
    ifYear = iyear - 621
    ifdayOfyear = idayOfyear - 79
    Else
    ifYear = iyear - 622
    ifdayOfyear = (iNumDayOfyear - 79) + idayOfyear
    End If


    ifday = ifdayOfyear
    While (ifday > aifMonthDays(ifmonth))
    ifday = ifday - aifMonthDays(ifmonth)
    ifmonth = ifmonth + 1
    Wend
    ifmonth = ifmonth + 1
    M2SDate = ifYear & "/" & ifmonth & "/" & ifday


    End Function
    Function isly(nyear)
    isly = (((nyear Mod 4) = 0 And (nyear Mod 100) <> 0) Or (nyear Mod 400) = 0)
    End Function

    Best regards.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Try the following. My change is in BLUE...

    Code:
    sql:
       
      SELECT Tasks_Recieved.ID_Recieved, Tasks_Recieved.Sender,  Tasks_Recieved.ID__RecievedDate, Tasks_Recieved.Documentcode,  Tasks_Recieved.Title, Tasks_Recieved.DocumentDate,  Tasks_Recieved.Priority, Tasks_Recieved.Status, Tasks_Recieved.[%  Complete], Tasks_Recieved.[Assigned To], Tasks_Recieved.Description,  Tasks_Recieved.[Due Date],  IIf(IsDate([Due Date]),M2SDate([Tasks_Recieved]![Due Date]),"") AS Farsi_Due_Date, Tasks_Recieved.Attachments, Tasks_Recieved.ID_Send
      FROM Tasks_Recieved;
    Also, in this line:

    Code:
    Dim iyear, idayOfyear As Long
    iyear is a variant and idayOfyeat is a long. If you want both to be longs, use:

    Code:
    Dim iyear As Long, idayOfyear As Long
    Same here:

    Code:
       Dim ifday As Long, ifmonth As Long, ifYear As Long, ifdayOfyear As Long

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

Similar Threads

  1. Replies: 1
    Last Post: 07-20-2011, 01:24 PM
  2. Replies: 1
    Last Post: 05-17-2011, 05:19 AM
  3. Replies: 9
    Last Post: 12-15-2010, 01:44 PM
  4. Replies: 3
    Last Post: 11-05-2010, 03:10 PM
  5. Replies: 2
    Last Post: 02-13-2010, 01:54 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