Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 34
  1. #16
    dancaw is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    13

    Its Been 10 Years Since i used Ms Access and cant remember half the stuff, i had learnt back then,

    everything I'm trying achieve, can be done just cant reminder how ? wish i still had that complete database :-(

    Attached is my DB (not finished)

    while your playing around, maybe you can have look why i cant get the filter to work on a subform combo box based on the first combo box nested under View Tenders clients - at the moment i can select client company, then i want to select to person from the company, at moment it pulls all people from all companies.

    Also trying to create a Manual auto increment text field on Tender_No (E0000A) looks at last number and adds +1 at moment i'm at E2173A

    Thanks Danny

    EMS - Copy.zip

  2. #17
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    I dont see that you included Daniels code you posted in post#4, namely the CopyFolder procedure.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #18
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    So I had to remove the reference to the calendar library, the library is missing on my machine at least and wouldn't allow the code to compile. Then I changed the code for frm_TenderView as follows and the [Create Folder] button now works. As Moke mentioned, you didn't have the code there for CopyFolder from post #4.

    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : CopyFolder
    ' Author : CARDA Consultants Inc.
    ' Website : http://www.cardaconsultants.com
    ' Purpose : Copy a folder
    ' Copyright : The following may be altered and reused as you wish so long as the
    ' copyright notice is left unchanged (including Author, Website and
    ' Copyright). It may not be sold/resold or reposted on other sites (links
    ' back to this site are allowed).
    '
    ' Input Variables:
    ' ~~~~~~~~~~~~~~~~
    ' sFolderSource Folder to be copied "Z:\Estimates\EstimateStructure"
    ' sFolderDestination Folder to copy to "Z:\Estimates"
    ' bOverWriteFiles Whether to overwrite file(s) if the folder already exists
    '
    ' Usage Example:
    ' ~~~~~~~~~~~~~~~~
    ' CopyFolder("Z:\Estimates", "Z:\Estimates\EstimateStructure", True)
    '
    ' Revision History:
    ' Rev Date(yyyy/mm/dd) Description
    ' ************************************************** ************************************
    ' 1 2010-Nov-14 Initial Release
    '---------------------------------------------------------------------------------------
    Function CopyFolder(sFolderSource As String, sFolderDestination As String, bOverWriteFiles As Boolean) As Boolean
    On Error GoTo Error_Handler
        Dim fs As Object
    
        CopyFolder = False
        Set fs = CreateObject("Scripting.FileSystemObject")
        fs.CopyFolder sFolderSource, sFolderDestination, bOverWriteFiles
        CopyFolder = True
    
    Error_Handler_Exit:
        On Error Resume Next
        Set fs = Nothing
        Exit Function
    
    Error_Handler:
        If Err.Number = 76 Then
            MsgBox "The 'Source Folder' could not be found to make a copy of.", _
            vbCritical, "Unable to Find the Specified Folder"
        Else
            MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
                "Error Number: " & Err.Number & vbCrLf & _
                "Error Source: CopyFolder" & vbCrLf & _
                "Error Description: " & Err.Description, _
                vbCritical, "An Error has Occurred!"
        End If
        Resume Error_Handler_Exit
    End Function
    
    Private Sub cmdRemove_Click()
        On Error Resume Next
        RunCommand acCmdDeleteRecord
    End Sub
    
    Private Sub cmd_openFile_Click()
        Application.FollowHyperlink Me!FolderLocation.Value
    End Sub
    
    Private Sub cmdHyperlink_Click()
        Dim fd As Object
        Set fd = Application.FileDialog(msoFileDialogFolderPicker)
        With fd
            .AllowMultiSelect = False
            If .Show Then
                Me.fld_folderlocation = .SelectedItems(1)
            End If
        End With
        
    End Sub
    
    Private Sub Command29_Click()
        CopyFolder "Z:\Estimates\EstimateStructure", "Z:\Estimates\" & Me.Tender_No & " - " & Me.Project_Title, False
    End Sub
    
    Private Sub Form_Load()
        DoCmd.GoToRecord , , acLast
    End Sub

  4. #19
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by dancaw View Post
    while your playing around, maybe you can have look why i cant get the filter to work on a subform combo box based on the first combo box nested under View Tenders clients - at the moment i can select client company, then i want to select to person from the company, at moment it pulls all people from all companies.
    It looks like your table tbl_ClientContacts doesn't reference the client table. It looks like you need to study up on relational database basics and specifically table relationships. You'll find plenty of introductory material online and on youtube.

    Also trying to create a Manual auto increment text field on Tender_No (E0000A) looks at last number and adds +1 at moment i'm at E2173A
    Need to know more about what exactly is happening here. What's the E and A? Do they ever change and how so?


    [EDIT]
    Ohhh I see what's going on with the combobox filter. You need to modifiy the row source query for cboClient (the contact combobox) to use tbl_ClientContacts and tbl_ClientContactLink, you don't need tbl_Clients. The rowsource query will look like this:
    Click image for larger version. 

Name:	deletethis.png 
Views:	27 
Size:	11.4 KB 
ID:	43852
    Code:
    SELECT tbl_ClientContacts.ContactID, tbl_ClientContacts.Contact_Name, tbl_ClientContactLink.ClientID
    FROM tbl_ClientContacts INNER JOIN tbl_ClientContactLink ON tbl_ClientContacts.ContactID = tbl_ClientContactLink.ContactID
    WHERE (((tbl_ClientContactLink.ClientID)=[Forms]![frm_TenderView]![sFrmTenderClients]![cboClients]));
    And then you need to modify the macro for the After Update event for cboClients to requrey cboClient (without the s). BTW these are confusing control names and might lead to more problems in the future.

  5. #20
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Gotcha. So if you apply the explanation I gave for ! vs . does that make sense? It does to me.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #21
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    Another thing I noticed is you have
    Code:
    CopyFolder "Z:\Estimates\EstimateStructure", "Z:\Estimates" & Me.Tender_No & " - " & Me.Project_Title, False
    Do you actually have a Z drive? I see that Daniels code uses the exact same structure in his example usage.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #22
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by Micron View Post
    Gotcha. So if you apply the explanation I gave for ! vs . does that make sense? It does to me.
    Yessir it does now!

  8. #23
    dancaw is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    13

    Thank you

    Quote Originally Posted by kd2017 View Post
    So I had to remove the reference to the calendar library, the library is missing on my machine at least and wouldn't allow the code to compile. Then I changed the code for frm_TenderView as follows and the [Create Folder] button now works. As Moke mentioned, you didn't have the code there for CopyFolder from post #4.

    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : CopyFolder
    ' Author : CARDA Consultants Inc.
    ' Website : http://www.cardaconsultants.com
    ' Purpose : Copy a folder
    ' Copyright : The following may be altered and reused as you wish so long as the
    ' copyright notice is left unchanged (including Author, Website and
    ' Copyright). It may not be sold/resold or reposted on other sites (links
    ' back to this site are allowed).
    '
    ' Input Variables:
    ' ~~~~~~~~~~~~~~~~
    ' sFolderSource Folder to be copied "Z:\Estimates\EstimateStructure"
    ' sFolderDestination Folder to copy to "Z:\Estimates"
    ' bOverWriteFiles Whether to overwrite file(s) if the folder already exists
    '
    ' Usage Example:
    ' ~~~~~~~~~~~~~~~~
    ' CopyFolder("Z:\Estimates", "Z:\Estimates\EstimateStructure", True)
    '
    ' Revision History:
    ' Rev Date(yyyy/mm/dd) Description
    ' ************************************************** ************************************
    ' 1 2010-Nov-14 Initial Release
    '---------------------------------------------------------------------------------------
    Function CopyFolder(sFolderSource As String, sFolderDestination As String, bOverWriteFiles As Boolean) As Boolean
    On Error GoTo Error_Handler
        Dim fs As Object
    
        CopyFolder = False
        Set fs = CreateObject("Scripting.FileSystemObject")
        fs.CopyFolder sFolderSource, sFolderDestination, bOverWriteFiles
        CopyFolder = True
    
    Error_Handler_Exit:
        On Error Resume Next
        Set fs = Nothing
        Exit Function
    
    Error_Handler:
        If Err.Number = 76 Then
            MsgBox "The 'Source Folder' could not be found to make a copy of.", _
            vbCritical, "Unable to Find the Specified Folder"
        Else
            MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
                "Error Number: " & Err.Number & vbCrLf & _
                "Error Source: CopyFolder" & vbCrLf & _
                "Error Description: " & Err.Description, _
                vbCritical, "An Error has Occurred!"
        End If
        Resume Error_Handler_Exit
    End Function
    
    Private Sub cmdRemove_Click()
        On Error Resume Next
        RunCommand acCmdDeleteRecord
    End Sub
    
    Private Sub cmd_openFile_Click()
        Application.FollowHyperlink Me!FolderLocation.Value
    End Sub
    
    Private Sub cmdHyperlink_Click()
        Dim fd As Object
        Set fd = Application.FileDialog(msoFileDialogFolderPicker)
        With fd
            .AllowMultiSelect = False
            If .Show Then
                Me.fld_folderlocation = .SelectedItems(1)
            End If
        End With
        
    End Sub
    
    Private Sub Command29_Click()
        CopyFolder "Z:\Estimates\EstimateStructure", "Z:\Estimates\" & Me.Tender_No & " - " & Me.Project_Title, False
    End Sub
    
    Private Sub Form_Load()
        DoCmd.GoToRecord , , acLast
    End Sub
    Works Like a Charm Thnak you very Much ..

  9. #24
    dancaw is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    13
    This In thoery should work,

    but its not - go some were wrong? im not sure if its to do with bound column is Numerical, but displaying column 2

    attached i what happens when i add the creteria [Forms]![frm_TenderView]![sFrmTenderClients]![cboClients]

    Click image for larger version. 

Name:	Capture 4.PNG 
Views:	24 
Size:	27.7 KB 
ID:	43855 Click image for larger version. 

Name:	Capture3.PNG 
Views:	23 
Size:	26.5 KB 
ID:	43856

    But if i remove the criteria filter and view it in query mode: Shows correct companies

    Click image for larger version. 

Name:	Capture 5.PNG 
Views:	23 
Size:	21.1 KB 
ID:	43857


  10. #25
    dancaw is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    13
    The E and A dont change now, but i have 3 years of data imported into the Tender Table..

    But they Started off been 0000 then they went to E0000 and now the last 2 years E0000A format

    So obviously in the table i could have 999 and a E999 and No E2999A and E

    Before my times, but they want to go back to be able to go back to the beginning..

  11. #26
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by dancaw View Post
    The E and A dont change now, but i have 3 years of data imported into the Tender Table..

    But they Started off been 0000 then they went to E0000 and now the last 2 years E0000A format

    So obviously in the table i could have 999 and a E999 and No E2999A and E

    Before my times, but they want to go back to be able to go back to the beginning..
    This is a very dumb function that will strip the first and last character off a string, convert the remaining characters to a number and add 1. By dumb I mean there is no built in flexibility, if your numbering scheme changes it'll likely break this function.
    Code:
    Public Function NextTenderNum(old_num As String) As String
        Dim prefix As String
        Dim suffix As String
        Dim seq As String
        
        ' extract the different parts of the number
        prefix = Left(old_num, 1)
        suffix = Right(old_num, 1)
        seq = Mid(old_num, 2, Len(old_num) - 2)
        
        ' convert the sequence number to an integer, add one, then convert back
        ' to a string. Make sure the number is padding with leading zeros if necessary
        seq = Format(Int(seq) + 1, "0000")
        
        'put them back together
        NextTenderNum = prefix & seq & suffix
    End Function

  12. #27
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by dancaw View Post
    This In thoery should work,

    but its not - go some were wrong? im not sure if its to do with bound column is Numerical, but displaying column 2


    Did you make all the changes I suggested above?

    Ohhh I see what's going on with the combobox filter.
    1. You need to modifiy the row source query for cboClient (the contact combobox) to use tbl_ClientContacts and tbl_ClientContactLink, you don't need tbl_Clients.
    2. And then you need to modify the macro for the After Update event for cboClients to requrey cboClient (without the s). BTW these are confusing control names and might lead to more problems in the future.
    It worked as expected when I made these changes.

  13. #28
    dancaw is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    13
    Quote Originally Posted by kd2017 View Post
    This is a very dumb function that will strip the first and last character off a string, convert the remaining characters to a number and add 1. By dumb I mean there is no built in flexibility, if your numbering scheme changes it'll likely break this function.
    Code:
    Public Function NextTenderNum(old_num As String) As String
        Dim prefix As String
        Dim suffix As String
        Dim seq As String
        
        ' extract the different parts of the number
        prefix = Left(old_num, 1)
        suffix = Right(old_num, 1)
        seq = Mid(old_num, 2, Len(old_num) - 2)
        
        ' convert the sequence number to an integer, add one, then convert back
        ' to a string. Make sure the number is padding with leading zeros if necessary
        seq = Format(Int(seq) + 1, "0000")
        
        'put them back together
        NextTenderNum = prefix & seq & suffix
    End Function
    Where do i add this code on the form load event?

  14. #29
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by dancaw View Post
    Where do i add this code on the form load event?
    This code is an independent function. You would place it in a module, or you could put it in form's code module. You would then call it from an event like this:
    Code:
    Dim new_num As String
    new_num = NextTenderNum( "E1234A" )
    Now the string new_num would contain the incremented tender number.

    It's likely that you'll need to look up the last tender number first. I assume you would look up the latest Tender_No in tbl_Tenders? And that if you sort by Tender_No in descending order than the first Tender_No is the latest Tender_No to increment? Here is a quick function that will lookup the latest tender no:
    Code:
    Public Function LastTenderNum() As String
    On Error GoTo ErrHandler_LastTenderNum
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim rslt As String
    
        Set db = CurrentDb
        Set rs = db.OpenRecordset("SELECT TOP 1 Tender_No FROM tbl_Tenders ORDER BY Tender_No DESC;")
        If Not (rs.BOF And rs.EOF) Then
            'Query found some records
            rslt = rs!Tender_No
        Else
            'Query didn't find anything
        End If
        rs.Close
    
    ExitHandler_LastTenderNum:
        Set rs = Nothing
        Set db = Nothing
        LastTenderNum = rslt
        Exit Function
    
    ErrHandler_LastTenderNum:
        MsgBox Err.Description, vbInformation, "LastTenderNo: Error #" & Err.Number
        Resume ExitHandler_LastTenderNum
    End Function
    That is another independent function that can be placed in a code module.

    So, now you can modify my first example like so to get the next tender no:
    Code:
    Dim new_num As String
    new_num = NextTenderNum( LastTenderNum() )
    *Note: your tbl_TenderView doesn't have a primary key. It looks like Tender_No used to be but it's index isn't flagged as unique so it won't function as a unique primary key. Also, you'd be better off just using an autonumber as a primary key instead.

    So now you need to decide how you want to call these functions to set the Tender_No field. The method I like to use would be to in the form's OnLoad event, I would check if the form was launched in data entry mode, and if it is I would set the *Default* value of the Tender_No textbox control using the code above like this:
    Code:
    Private Sub Form_Load()
        If Me.DataEntry Then 'form was loaded in data entry mode to enter a new record
            Me.Tender_No.DefaultValue = NextTenderNum(LastTenderNum())
        Else 'form was loaded to browse existing records
            Me.Tender_No.DefaultValue = ""
        End If
    End Sub
    You would open the form in data entry mode like this:
    Code:
    docmd.OpenForm "frm_TenderView", , , , acFormAdd
    This is all untested!

    [Edit] On second thought I'd probably move that last bit to the On Current event of the form. Also noticed an error in regard to enclosing the default value with quotation marks

    Code:
    Private Sub Form_Current()
        If Me.NewRecord Then 'form has moved to a new record
            Me.Tender_No.DefaultValue = """" & NextTenderNum(LastTenderNum()) & """"
        Else 'form is browsing existing records
            Me.Tender_No.DefaultValue = "" 'probably not necessary
        End If
    End Sub

  15. #30
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    It's likely that you'll need to look up the last tender number first. I assume you would look up the latest Tender_No in tbl_Tenders? And that if you sort by Tender_No in descending order than the first Tender_No is the latest Tender_No to increment?
    Assuming Tender_No is a string it will not sort in numerical order.
    Code:
    1
    101
    102
    103
    104
    105
    106
    107
    108
    109
    11
    110
    Etc…
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Create folder shortcut
    By Robyn_P in forum Programming
    Replies: 3
    Last Post: 03-27-2020, 09:15 AM
  2. Create A Folder With Textbox Value
    By Eranka in forum Access
    Replies: 10
    Last Post: 06-25-2018, 09:02 AM
  3. Create a folder into a network location
    By charly.csh in forum Access
    Replies: 7
    Last Post: 12-04-2015, 10:02 AM
  4. VBA to create PDF and folder if doesn't exist!
    By crxftw in forum Programming
    Replies: 2
    Last Post: 08-08-2011, 08:53 AM
  5. create On Click to go to specific server folder
    By airhud86 in forum Programming
    Replies: 1
    Last Post: 01-05-2010, 12:45 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