Results 1 to 4 of 4
  1. #1
    RedWolf3x is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Jul 2011
    Posts
    31

    SOLVED VBA excluding (Ignoring) Comma


    Ok so here is the problem. I currently have a form with a combo box. And several text boxes. The combo box is tied to a list of Names (Formatted "Lastname, Firstname")The Text boxes pull data from a table based off the name in the drop down box. This works fine using the next record or search feature. I'm trying to write a macro so that once a name is selected in the combo box it automatically updates the text boxes. Below is the code I'm using, however I get an error because all of the names have a comma in them. How can I get VBA to ignore the comma?

    Code:
     
    DoCmd.FindRecord DLookup("CSRName", "CSR Stats", "CSRName =" & Forms![Statistical Score Form]!Combo293.Value & ""), , True, , True
    Thanks.

    -Red
    Last edited by RedWolf3x; 11-11-2011 at 05:15 PM.

  2. #2
    Toyman is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    233
    Quote Originally Posted by RedWolf3x View Post
    Ok so here is the problem. I currently have a form with a combo box. And several text boxes. The combo box is tied to a list of Names (Formatted "Lastname, Firstname")The Text boxes pull data from a table based off the name in the drop down box. This works fine using the next record or search feature. I'm trying to write a macro so that once a name is selected in the combo box it automatically updates the text boxes. Below is the code I'm using, however I get an error because all of the names have a comma in them. How can I get VBA to ignore the comma?

    Code:
     
    DoCmd.FindRecord DLookup("CSRName", "CSR Stats", "CSRName =" & Forms![Statistical Score Form]!Combo293.Value & ""), , True, , True
    Thanks.

    -Red
    Try this:
    DLookup("CSRName", "CSR Stats", "CSRName ='" & Forms![Statistical Score Form]!Combo293.Value & "'"), , True, , True

  3. #3
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Well, first thing to address is this incorrect syntax:

    "CSRName =" & Forms![Statistical Score Form]!Combo293.Value & "")

    It should be:

    "CSRName =" Chr(34) & Forms![Statistical Score Form]!Combo293.Value & Chr(34))

    You have to have the quotes for delimiting text values. If CSRName is text then you need those. However, if CSRName is text and the combo is selecting a NUMBER (ID) then you need to refer to the right combo of the combo box to go with the text:

    "CSRName =" Chr(34) & Forms![Statistical Score Form]!Combo293.Column(1) & Chr(34))

    Where Column(1) is the second column as it is zero-based.

    Also, you can use single quotes instead of Chr(34) but I find those to be problematic with some names like O'Hara, O'Neil, etc. Or you can use triple double quotes (""") but that quickly gets hard to read. So I like using Chr(34) instead.


  4. #4
    RedWolf3x is offline Advanced Beginner
    Windows 7 32bit Access 2003
    Join Date
    Jul 2011
    Posts
    31
    Thank you both for your help, unfortunately I was not able to get either of those to work properly (I blame my poor VBA experience). However I completely missed the fact that what I was trying to accomplish was already a built in function of Access. So I've gotten it to work. Thank you both again.

    -Red

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

Similar Threads

  1. SQL wildcard character excluding
    By sandlucky in forum Access
    Replies: 2
    Last Post: 03-28-2011, 03:33 AM
  2. DateDiff Excluding Weekends
    By cs93 in forum Programming
    Replies: 1
    Last Post: 03-25-2011, 04:09 PM
  3. Weekday excluding weekends
    By jd316632 in forum Queries
    Replies: 3
    Last Post: 05-24-2010, 02:01 PM
  4. Excluding data in a query
    By lpdds in forum Queries
    Replies: 1
    Last Post: 12-16-2009, 08:06 PM
  5. Replies: 2
    Last Post: 08-31-2006, 12:19 PM

Tags for this Thread

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