Results 1 to 6 of 6

Thread: Access Expression Builder

  1. #1
    Registered+
    Join Date
    Dec 2004
    Posts
    49
    Thanks
    0
    Thanked
    0 times in 0 posts

    Access Expression Builder

    Im doin some work in Access and wanted to know what im doin wrong in the expression builder on a Products table.

    I need the price field (type=currency), to have the following validation rule.
    Price should be grater than zero and price cannot be a null entry.

    Ive got the [Price] >0 but dont know how to tell it that Price should not be a null entry.

    Help Appriciated
    Thanks

  2. #2
    Pixel Abuser Spunkey's Avatar
    Join Date
    Nov 2003
    Location
    Milton Keynes
    Posts
    1,523
    Thanks
    0
    Thanked
    0 times in 0 posts
    Open the table in design view, and put the 'Required' value to yes for the field. Thats Access' way of disallowing null values - you shouldnt need to use validation rules to set it.

    You could also include a default value to ensure none slip through in code.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    2
    Thanks
    0
    Thanked
    0 times in 0 posts

    Need help with an expression

    In Access, I have a form with a text box. The only validation rule that I need is that a value of 7 numbers can only be entered into it. No decimals or negative numbers or anything.. just a straight 7 positive digits, and no more or no less. I tried using the expression builder for the first time ever and inputting: [Case ID].SelLength = 7
    (Case ID is my text box name)

    It doesn't work though. Can someone help??
    Thank you!
    jk

  4. #4
    Pixel Abuser Spunkey's Avatar
    Join Date
    Nov 2003
    Location
    Milton Keynes
    Posts
    1,523
    Thanks
    0
    Thanked
    0 times in 0 posts
    Assuming the textbox is databound to a field in a table, make sure the field in the table is of 'number' type, then when in design mode of the form, set the validation rule as..
    Code:
    Like "???????"
    This means that the entry MUST be 7 characters, and because the field is numeric, it will only allow valid numbers.

    If the textbox is not databound, you'll need to put some code in to validate it.
    On the Events tab of the properties window for the textbox, select 'Event Procedure' and then click the '...' button.
    In the code window which appears, enter this in the Sub...
    Code:
      If not isNumeric(TextboxName.value) then
        ' not a valid number
        msgbox("Enter a number jackass")
        Exit Sub
      Else
        ' it is a valid number
        If TextboxName.value <= 0 then
          ' its a negative number
          msgbox("Enter a positive number jackass")
          Exit Sub
        Else
          ' its a number, and its not negative
          If len(TextboxName.value & "") < 7 then
            ' Its not 7 characters
            msgbox("Enter a 7 digit number jackass")
            Exit Sub
          Else
            ' its a number, its not negative and its 7 characters - SUCCESS!
            ' Its valid, carry on processing your form, shove it in 
            ' the database, whatever you wanna do
          End If
        End If
      End If
    OK thats got more nested IF's than you can shake a big pointy stick at, but it should work

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    2
    Thanks
    0
    Thanked
    0 times in 0 posts

    It works!

    Excellent. That works. I also found I could input 0000000 in the Input Mask, but that was causing the cursor to jump to the end and I couldn't enter the numbers without highlighting the field. Your way works much better. The text box was bound to a table field.. so your short approach worked great! Thanks!!

    As a follow up, I can now enter a new record and save it without a problem, but I don't like that you don't get any kind of prompt that the record is saved. Is there an ez way to accomplish this?

    Thanks again! The part I really need answered now works well!
    jk

  6. #6
    Pixel Abuser Spunkey's Avatar
    Join Date
    Nov 2003
    Location
    Milton Keynes
    Posts
    1,523
    Thanks
    0
    Thanked
    0 times in 0 posts
    glad it worked matey

    I've never done the message after an update thing, but i can see why you want it. Access forms don't update a record until you move off it - as the tables do. I've never tried it, but give the below a go.

    If you click on the area outside your form in design view, and go to the Events window in properties. Now, if you just want to popup a message after an insert, change the 'After Insert' to Event Procedure and click the dots. In the Sub which appears enter...
    Code:
    msgbox("Record has been successfully inserted")
    To do the same for an Update to a record, you'll need to set the 'After Update' event on the props window.

    Can't guarantee it'll work, but it's worth a shot

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 05-02-2005, 03:53 PM
  2. Wireless access point as NIC
    By hotpurple in forum Networking and Broadband
    Replies: 10
    Last Post: 24-08-2004, 10:25 AM
  3. Can't access folders or printers from my laptop on network
    By TomWilko in forum Networking and Broadband
    Replies: 15
    Last Post: 02-12-2003, 09:44 AM
  4. Access Reports - help....
    By Lead_Head in forum Software
    Replies: 5
    Last Post: 22-10-2003, 12:19 PM
  5. NT4 Domain - A: drive access
    By joshwa in forum Software
    Replies: 1
    Last Post: 27-08-2003, 09:07 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
  •