Results 1 to 4 of 4
  1. #1
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162

    Can anyone see why this isnt working please?


    Hi,

    Im trying to take a value from me.hour and if its a positive number convert it to CD and if its negative convert to CC. Below is my code
    Code:
    sHourType = Me.Hour.Value
    sCostCode = Me.CostCode
    sActivity = Me.Activity.Column(0)
    sProject = Me.Project
    sHours = Nz(Me.Hour, 0)
    sDescript = Nz(Me.Description, " ")
    Me.Description = sDescript
    sLogUser = Me.LoggedInUser
    sDate = Me.DatePicker
    sProjectRef = Me.Project.Column(2) & "-" & Me.SubProjectCode
    If sHourType <> 0 Then
    sHourType = "CD"
    Else
    sHourType = "CC"
    End If
    Currently regardless if its +'ve or -'ve it comes back CD. Can anyone spot what I am doing wrong?

    Thanks

  2. #2
    SteveH2508 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Location
    Chelsea, London, England
    Posts
    117
    Code:
    If sHourType <> 0 Then
         sHourType = "CD"
    Else 
         sHourType = "CC" 
    End If
    <> means not equal to - you need > in your expression.

    You have a few other potential problems as well.

    You are using several reserved words as field names.

    Hour
    Project
    Description

    are all words with a specific meaning in Access/VBA.

    What datatype is sHourType meant to be?

    It seems confused as to whether it is numeric or a string.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,740
    Further to SteveH2508 response,
    -you should get familiar with debug.print as a debugging tool. Print the values of various fields; and
    -learn to step through your code (F8)
    - avoid Reserved words see http://allenbrowne.com/AppIssueBadWord.html
    -get consistent with your names , usually s.... is used for string datatype.

  4. #4
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    Ah ok great - that works. sHourType is a string as its text but the me.hours is a number as I wanted to get a text value and numeric value from one input.

    I must get my head around using the de bug tool as you say its handy - but it never seems to work properly for me. Probably because I dont understand it

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

Similar Threads

  1. Could someone explain why this code isnt working please?
    By shabbaranks in forum Programming
    Replies: 7
    Last Post: 10-29-2011, 09:14 AM
  2. Replies: 4
    Last Post: 01-31-2011, 03:19 PM
  3. Replies: 7
    Last Post: 12-14-2010, 11:10 AM
  4. Why isn't this working?
    By adiecidue in forum Queries
    Replies: 4
    Last Post: 04-27-2009, 10:29 AM
  5. Combo Box isnt saving
    By calisen in forum Access
    Replies: 0
    Last Post: 09-11-2008, 03:34 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