Results 1 to 6 of 6
  1. #1
    JonMulder is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    24

    FindFirst Not Working with Decimal Data Type

    I've got a bunch of tables that I'm linking to that have Primary fields as a Decimal Data Type. Actually, ALL of the number fields are of Decimal Data Type. I want to do a "FindFirst" to locate the first (and only) record that has, for example, "MASTER_SITE_ID = 49033". Prior to the FindFirst, I have some code to get the user to select a MASTER_SITE_ID from a listbox, then define a Variant variable for the Decimal Data Type. Here's a snippet of my code:



    Private Sub CmdAddGridWell_Click()
    Dim booWellNotInGridWellTable As Boolean
    booWellNotInGridWellTable = True
    Do While booWellNotInGridWellTable
    DoCmd.OpenForm "GetWellLocation_CASGEMWells", , , , , acDialog
    If pubvarMASTER_SITE_ID = "" Then
    Exit Sub
    End If
    'Check that CASGEM Well Record is not already linked to a GridWell Record.
    Dim dbs As Database
    Dim rstGridWells As Recordset
    Set dbs = CurrentDb()
    Set rstGridWells = dbs.OpenRecordset("Query--GridWells", dbOpenDynaset)
    rstGridWells.FindFirst "MASTER_SITE_ID = " & CDec(pubvarMASTER_SITE_ID)
    ''' The following code did not work.''' rstGridWells.FindFirst "MASTER_SITE_ID = '" & pubvarMASTER_SITE_ID & "'"
    If rstGridWells.NoMatch Then
    Exit Do
    Else
    Dim intResponse As Integer
    Call PlaySound("OhOh.wav")
    intResponse = MsgBox("This well is already linked to a Grid Well." & vbNewLine & "Do you want to view well data?", vbYesNo, "Well Already Linked to a Grid Well")
    If intResponse = 6 Then
    DoCmd.OpenForm "Form--ViewWellData"
    End If
    Exit Sub
    End If
    Loop
    DoCmd.OpenForm "Form--EditGridWellData", , , , acFormAdd, acDialog
    End Sub

    I've tried using the CDec function, but that doesn't seem to work. I've read a lot about how Decimal Data Types are not very "VBA-friendly", and I would prefer not to have to deal with them. However, unfortunately, I am LINKED to these tables and have to deal with them as they are.

    Any suggestions on what I can do, or what I'm doing wrong? Thanks in advance for any help!

    Jon Mulder
    Engineering Geologist, California Department of Water Resources, Red Bluff CA

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Decimal is not actually a Data Type. It is parameter of FieldSize property of Number Data Type

    I tried to replicate the issue and can't. FindFirst works fine even if field is set for Decimal FieldSize.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    JonMulder is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2011
    Posts
    24
    Then maybe my syntax is wrong for the pubvarMASTER_SITE_ID. I've "dimmed" it as a variant.

    I had seen a lot of chatter about the Decimal Data Type not being for "friendly" in VBA; thought that might be my problem.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Variant declaration makes no difference in my code.

    I've never set number types as Decimal but my simple procedure is not having issue. I am using Access 2010 but hopefully that doesn't matter.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    First off I'd place all of your Dim statements at the beginning of you Sub; I've seen cases where having Dim statements in the body of the Sub rather than at the top of the Sub caused problems. Then replace

    Code:
    Dim rstGridWells As Recordset

    with
    Code:
    Dim rstGridWells As DAO.Recordset

    and see what happens. I'd leave the above in place, as stated, even if it doesn't resolve the current problem. It should be in place in this manner, regardless.

    It this doesn't work, try replacing
    Code:
    rstGridWells.FindFirst "MASTER_SITE_ID = " & CDec(pubvarMASTER_SITE_ID)
    with
    Code:
    rstGridWells.FindFirst "MASTER_SITE_ID = """ & CDec(pubvarMASTER_SITE_ID) & """"

    and see what happens.

    Linq ;0)>

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    If Master_Site_ID is a number field then the double quote (or apostrophe) delimiters will cause error. Did you try simply:

    rstGridWells.FindFirst "MASTER_SITE_ID = " & pubvarMASTER_SITE_ID


    If it is a text data type then the CDec conversion should not be necessary.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 7
    Last Post: 09-28-2023, 08:41 AM
  2. Replies: 5
    Last Post: 01-14-2013, 03:04 PM
  3. Recordset FindFirst Not Working
    By ShoresJohn in forum Programming
    Replies: 5
    Last Post: 03-01-2012, 06:59 PM
  4. Replies: 2
    Last Post: 03-18-2010, 08:24 PM
  5. Attachment data type INSERT INTO not working
    By LouisLouis in forum Programming
    Replies: 0
    Last Post: 09-27-2009, 02:23 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