Results 1 to 30 of 30

Thread: OLD SOURCE CODE need Help!!!

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    OLD SOURCE CODE need Help!!!

    this is the code i have and i want to know what it does so i can make a query from it


    Code:
    Private Sub cmdCheck_Click()
    Dim q As QueryDef
    Dim rs As Recordset
    Dim CountStr As String
    Dim Count As Long
        If Len(txtFirstName) = 0 Then
            MsgBox "Please enter a first name", vbCritical, "LegalSOFT"
            Exit Sub
        End If
        
        If Len(txtLastName) = 0 Then
            MsgBox "Please enter a last name", vbCritical, "LegalSOFT"
            Exit Sub
        End If
        
        
        Set q = CurrentDB.QueryDefs("int_qGetCodeCount")
        q.Parameters("pCode") = UCase(MakeCode)
        Set rs = q.OpenRecordset
        
            If rs.RecordCount = 0 Then
                Count = 1
            Else
                Count = rs("MaxCode") + 1
            End If
        CountStr = Format(Count, "000")
        txtCode = UCase(MakeCode) & CountStr
        cmdSave.Enabled = True
        
        
        
    End Sub
    thanks

  2. #2
    Member
    Join Date
    Mar 2010
    Posts
    61

    Re: OLD SOURCE CODE need Help!!!

    Maybe you should've read it and the page you copy and pasted it from?

  3. #3
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: OLD SOURCE CODE need Help!!!

    I'm not familiar with MS Access but it's doing some validation on the first and last name and setting up an update. Do you have a specific question about it?

  4. #4
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: OLD SOURCE CODE need Help!!!

    If Len(txtFirstName) = 0 Then

    checks the length of the string (Text) in the textbox named txtFirstName. If it is 0, it means it's empty and it gives the error message and aborts/exits the procedure.

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    i have an already compile version of the software but is using newer code and i just have the original (first) source code.

    this is what the software does

    we enter "last name" and "fist name"
    ex.
    "Jackson" "Michael"

    the software then makes a code out of it
    something like this
    JACKMI001

    the software looks for a query on the database and if there is another client with the same code (JACKMI001) then it adds a 1 to the counter which ends up like
    JACKMI002

    the software is suppose to do this but i cant (idk) how to make a query to do this or the software do this.

    again thanks for your time and help

  6. #6
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: OLD SOURCE CODE need Help!!!

    I'm confused at what your question is... what you just described above seems to be exactly what the code is doing. What exactly is your issue?

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    I dont have the query on my database and i dont khow how to make one that would give me the result the code is asking me for

    Thanks

  8. #8
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: OLD SOURCE CODE need Help!!!

    Here is some generic code... You would have to know the table name the query is referring too.

    vb Code:
    1. Private Sub cmdCheck_Click()
    2. Dim q As QueryDef
    3. Dim rs As Recordset
    4. Dim CountStr As String
    5. Dim Count As Long
    6.    
    7. If Len(txtFirstName) = 0 Then
    8.     MsgBox "Please enter a first name", vbCritical, "LegalSOFT"
    9.     Exit Sub
    10. End If
    11.    
    12. If Len(txtLastName) = 0 Then
    13.     MsgBox "Please enter a last name", vbCritical, "LegalSOFT"
    14.     Exit Sub
    15. End If
    16.  
    17. 'Assuming that MakeCode is set somewhere else???
    18.  
    19. rs.Source = ("SELECT MAX(pcode) as ""MaxCode"" FROM [table_name] WHERE pcode = '" + UCase(MakeCode) + "'")
    20.  
    21. rs.Open
    22.  
    23. If rs.RecordCount = 0 Then
    24.     Count = 1
    25. Else
    26.     Count = rs!MaxCode + 1
    27. End If
    28.  
    29. rs.close
    30.  
    31. CountStr = Format(Count, "000")
    32. txtCode = UCase(MakeCode) & CountStr
    33.  
    34. cmdSave.Enabled = True
    35.    
    36. End Sub
    Last edited by Chrissy; Oct 1st, 2010 at 02:17 PM.

  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    so by doing this how would the query look like

  10. #10
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: OLD SOURCE CODE need Help!!!

    This is the query... Instead of putting it in the database, you can just add it in the code.

    Code:
    ("SELECT MAX(pcode) as ""MaxCode"" FROM [table_name] WHERE pcode = '" + UCase(MakeCode) + "'")
    You need to fill the appropriate table name in. I can't be more specific because I don't know what your database looks like. Basically this should return the maximum value of pcode in the database.

  11. #11

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    where do i place this

  12. #12
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: OLD SOURCE CODE need Help!!!

    Did you try the code I gave you? The query is in there... you need to replace the [table_name] with the actual name of the table.

  13. #13

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    I tried it already

    i removed this part and added yours

    Code:
    Set q = CurrentDB.QueryDefs("int_qGetCodeCount")
        q.Parameters("pCode") = UCase(MakeCode)
        Set rs = q.OpenRecordset

  14. #14
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: OLD SOURCE CODE need Help!!!

    Are you getting an error? I can't help you if you are not specific...

  15. #15

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    i get an error when i click check

    i can print screen the error if u want or stream it

  16. #16

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    this is the error i'm getting

  17. #17

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    compilation error
    Could not find the method or data member

    the version we have here is in spanish

  18. #18

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    this is the code i have. the table is "tblCustomer"


  19. #19

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    this is what i get on Visual Basic after the compilation error


  20. #20
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: OLD SOURCE CODE need Help!!!

    Can you show me the references that are in your project?

  21. #21
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: OLD SOURCE CODE need Help!!!

    You also need to set the recordset to the connection... Add this before rs.Source. I don't think it will fix your problem, but you will need it regardless.

    vb Code:
    1. Set rs = New Recordset
    2. 'Conn is whatever your connection object is defined as.
    3. rs.ActiveConnection = Conn


    Also you may need to ad a "Group By" clause in the SELECT statement... not sure.

  22. #22

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    which references. database location or what

  23. #23
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: OLD SOURCE CODE need Help!!!

    Under Project >> References... which references do you have added to your project. You can just show me a screen shot.

  24. #24

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    here is the reference. Sorry i took long


  25. #25
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: OLD SOURCE CODE need Help!!!

    Try selection the Microsoft ActiveX Data Objects Recordset Library too. Then try this for your code.

    vb Code:
    1. Private Sub cmdCheck_Click()
    2. Dim q As QueryDef
    3. Dim rs As ADODB.Recordset
    4. Dim CountStr As String
    5. Dim Count As Long
    6.    
    7. If Len(txtFirstName) = 0 Then
    8.     MsgBox "Please enter a first name", vbCritical, "LegalSOFT"
    9.     Exit Sub
    10. End If
    11.    
    12. If Len(txtLastName) = 0 Then
    13.     MsgBox "Please enter a last name", vbCritical, "LegalSOFT"
    14.     Exit Sub
    15. End If
    16.  
    17. Set rs = New ADODB.Recordset
    18.  
    19. 'Conn is whatever your connection object is defined as... is that CurrentDB?
    20. rs.ActiveConnection = Conn
    21.  
    22. rs.Source = ("SELECT MAX(pcode) as ""MaxCode"" FROM tblCustomer WHERE pcode = '" + UCase(MakeCode) + "'")
    23.  
    24. rs.Open
    25.  
    26. If rs.RecordCount = 0 Then
    27.     Count = 1
    28. Else
    29.     Count = rs!MaxCode + 1
    30. End If
    31.  
    32. rs.Close
    33.  
    34. CountStr = Format(Count, "000")
    35. txtCode = UCase(MakeCode) & CountStr
    36.  
    37. cmdSave.Enabled = True
    38.    
    39. End Sub

  26. #26

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    Thanks for the help but its not working
    I added the reference u told me but had no luck and got the compilation error

    i think i can make it work if i figure out how to make query on access

    i need a query that counts the amount of
    code names without the numbers at the end

    ex

    AGUIAN001
    AGUIAN002
    AGUIAN003

    COUNT ONLY THE AMOUNT OF
    AGUIANXXX

  27. #27
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: OLD SOURCE CODE need Help!!!

    MS SQL
    select count(*) from YourTable where substring(ColumnName,1,6) = 'Aguian'

  28. #28
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: OLD SOURCE CODE need Help!!!

    I don't think you want to use Count(). You are then assuming that all the AGUIAN records are in order starting at one. This would also assume that no records were deleted. I think you should use the MAX() function. This will return the last number used... You are basically creating the primary key for a record correct?

    The following SQL statement also assumes that pcode is the name of the field that holds the data you are referencing.

    Code:
    select MAX(pcode) from tblCustomer where pcode LIKE 'AGUIAN*'

  29. #29

    Thread Starter
    Member
    Join Date
    Mar 2010
    Posts
    40

    Re: OLD SOURCE CODE need Help!!!

    'Conn is whatever your connection object is defined as.

    what would this look like?

    like this
    rs.ActiveConnection = CurrentDB ??????

  30. #30
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: OLD SOURCE CODE need Help!!!

    I can't see how CurrentDB is defined... is it defined as a Connection? If so, that would be correct.

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
  •  



Click Here to Expand Forum to Full Width