none
combine 2 code to 1 RRS feed

  • Question

  • i have 1 code for login and print a daily job for employed 

    Dim rs As Recordset 
    Set rs=CurrentDb.OpenRecordset("tblimployd",dbOpenSnapshot,dbReadOnly)         
    rs.FindFirst "username='" & Me.txtusername & "'"        
    If rs.NoMatch Then       
     Me.lblWrongUser.Visible = True        
    Me.txtusername.SetFocus        
    Exit Sub    
    End If    
    Me.lblWrongUser.Visible = False       
     If rs!password <> Nz(Me.txtpassword, "") Then        
    Me.lblwrongpass.Visible = True       
     Me.txtpassword.SetFocus        
    Exit Sub   
     End If   
     Me.lblwrongpass.Visible = False  
     DoCmd.OpenReport "rpttodo", acViewNormal, , "[operator] = '" & Me.txtusername & "'"   
     DoCmd.Close acForm, Me.Name
    now i have another code to mark a field yes/no if the report already printed before 
    Private Sub btn334_Click()
    DoCmd.PrintOut PrintRange:=acPrintAll, PrintQuality:=acHigh, CollateCopies:=True
    Dim rst As RecordsetSet 
    rst = CurrentDb.OpenRecordset(Name:="qrytodo",Type:=RecordsetTypeEnum.dbOpenDynaset)
    Do While Not rst.EOF 
    CurrentDb.Execute "update qrytodo set printed=true where printed=false"      
     rst.MoveNext
    Loop
    how do i combine those 2 code to one procedure 

    Saturday, October 8, 2016 11:36 PM

Answers

  • Hi Eshay1,

    is there any connection between these 2 database?

    Are you able to access the data from one database to another?

    if yes , then you can use the Application.Run as I mentioned in my last post.

    if no, then you will not able to run it from end user because any connection is not available to connect these two databases.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 11, 2016 5:04 AM
    Moderator

All replies

  • You can do that several ways. Maybe the simplest is at the bottom of the first procedure write:

    btm334_Click

    That would run the click event. It's just another Sub you can run at will.

    Horrible name for an event procedure, BTW.

    The btn334 procedure itself is also very suspicious. You're looping over the recordset, but then inside of the loop you don't use any of its values? Seems fishy to me. You may have abbreviated the code so more power to you :-)


    -Tom. Microsoft Access MVP

    Sunday, October 9, 2016 1:26 AM
  • thank you 

    the btn334 code work on a different report that have the worker name

    and its connect to aquiry of the worker so the "qrytodo" change to "qryworkername" and its work good

    now i'm stuck  because the first code is in a end user db

    and the btn334 is on the main db

    so what i need is after the worker log in and print is daily job the printed field must change to true to prevent duplicate jobs printing

    Sunday, October 9, 2016 1:54 AM
  • Hi Eshay1,

    you had mentioned that,"now i'm stuck  because the first code is in a end user db and the btn334 is on the main db".

    so you want to call the sub from different database.

    so you need to use Application.Run.

    This method is useful when you are controlling Microsoft Access from another application through Automation, formerly called OLE Automation. For example, you can use the Run method from an ActiveX component to carry out a Sub procedure that is defined within a Microsoft Access database.

    Example:

    Dim appAccess As New Access.Application 
    appAccess.OpenCurrentDatabase ("C:\My Documents\WizCode.mdb") 
    appAccess.Run "WizCode.NewForm", "Some String"
    

    If another procedure with the same name may reside in a different database, qualify the procedure argument, as shown in the preceding example, with the name of the database in which the desired procedure resides.

    You can also use the Run method to call a procedure in a referenced Microsoft Access database from another database.

    For more information regarding Application.Run visit the link mentioned below.

    Application.Run Method (Access)

    Regards

    Deepak



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, October 10, 2016 5:43 AM
    Moderator
  • first thank you all and i'm sorry

    I mixed up the question

    the first code is on the end user db. a worker login and its automtic print is daily job

    the second code is in my office on the main db. the code print the report and marked the field yes/no to yes to know what jobs was printed 

    now the second code was first then i add a printer to the end user and add the first code (now the don't have to Come to my office)

    In conclusion i need to put the 2 codes in the end user db so the report well be printed by the login and marked the field yes\no to yes

     Regards

    eshai

    Monday, October 10, 2016 9:06 PM
  • Hi Eshay1,

    is there any connection between these 2 database?

    Are you able to access the data from one database to another?

    if yes , then you can use the Application.Run as I mentioned in my last post.

    if no, then you will not able to run it from end user because any connection is not available to connect these two databases.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 11, 2016 5:04 AM
    Moderator