Dmax switched value from string to number(long)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • david sheets
    New Member
    • Dec 2010
    • 1

    Dmax switched value from string to number(long)

    Hello All,

    The code below worked when wjem the DrawingID was a text, i switched it to a number now my database went to S**T. I am an engineer and new to coding and need to get this out the door today, or its my ass. Anyone have any suggestions? I have allready tried Dim MaxComponentID As long and Dim MaxComponentID As variant. Any other sugestions? I am not sure if this maters the format for drawing ID is 00 Long Interger. Code below

    Code:
    Private Sub Command14_Click()
    
        Dim AssyIDvalue As String
        AssyIDvalue = Me.AssemblyID.Value
        Dim MaxComponentID As String
        MaxComponentID = DMax("DrawingID", "Assemblylog", "[AssemblyID]='" & AssyIDvalue & "'") + 1
        Forms!frmAddComponent!DrawingId.Value = MaxComponentID
        DoCmd.GoToRecord , , acNewRec
        stDocName = "frmSubAssemblylog"
        DoCmd.Close acForm, "frmAddComponent"
        Forms!frmstorage!Text0.Value = AssyIDvalue
        DoCmd.OpenForm stDocName ', , , stLinkCriteria
    End Sub
    Last edited by NeoPa; Dec 16 '10, 06:00 PM. Reason: Added code tags
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    When using a string/text field in a ciriteria (where) expresion the argument needs enclosing in apostrophies, as you have done so far.

    However, for a number field the argument does not need apostrophies, ie.

    MaxComponentID = DMax("DrawingID ", "Assemblylo g", "[AssemblyID]= " & AssyIDvalue ) + 1

    HTH

    MTB

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32656

      #3
      If you look at line #5 you'll see the variable you store the result in is Dimmed as a String.

      It's always a good idea to keep all your (procedure) Dim statements at the top of your procedures. That way such things aren't so well hidden.

      If that doesn't resolve your problem, then I suggest you tell us more accurately what your problem is. Saying something has gone to S**T is unlikely to shock, but it isn't very helpful for communicating information either. At this point all we know is that something, somewhere, isn't working for you. Knowing what that is, and especially where it occurs, would be much more helpful in allowing us to resolve this problem for you before it gets too late.

      Comment

      Working...