combine 2 code to 1

eshai

Registered User.
Local time
Today, 22:59
Joined
Jul 14, 2015
Messages
195
i have 1 code for login and print a daily job for employed
Code:
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
Code:
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
Loope
how do i combine those 2 code to one procedure
 
Um, copy and paste?
i wish but it's complicated each code is in a different db
i have to combine the 2 code to one code that will execute when the user log in
 
not quite clear what you are trying to do but perhaps something along these lines to open recordsets from two different dbs


Code:
dim ws as workspace
dim db1 as dao.database
dim db2 as dao.database
dim rst1 as dao.recordset
dim rst2 as dao.recordset

set ws=dbegine.workspaces(0)
set db1=currentdb
set db2=ws.opendatabase(pathtoseconddatabase)

set rst1=db1.openrecordset("tblimployd",dbOpenSnapshot,dbReadOnly) 
set rst2=db2.openrecordset(Name:="qrytodo",Type:=RecordsetTypeEnum.dbOpenDynaset)
 
not quite clear what you are trying to do but perhaps something along these lines to open recordsets from two different dbs

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
 
why not just copy and paste the code?

I'm struggling to understand what the problem actually is
 
because in my office i have query for every employed and a report.
in the report is the btn334 function that do the yes/no
and in the end user db i have only one query and report
so i need the second code to do a filter by the first code
 
I still don't understand why not include btn334 in the enduser db?

You need to be much clearer
 
I don't see why you open this recordset and loop thru it...
Code:
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
Loope
This query...
Code:
CurrentDb.Execute "update qrytodo set printed=true where printed=false"
...when executed once, does nothing more if executed again, so to execute it inside a loop is pointless. This routine should just do...
Code:
DoCmd.PrintOut PrintRange:=acPrintAll, PrintQuality:=acHigh, CollateCopies:=True
CurrentDb.Execute "update qrytodo set printed=true where printed=false"
Hope this helps,
 
thank you but the code marking the all employed as yes when i need only to employed that login to get marked as yes
 
Why not just add the update that the report has been printed for a particular user immediately after the report printing

Code:
Docmd.openreport .....
CurrentDb.Execute "update qrytodo set printed=true where [operator] = '" & Me.txtusername & "'"
 
Why not just add the update that the report has been printed for a particular user immediately after the report printing

Code:
Docmd.openreport .....
CurrentDb.Execute "update qrytodo set printed=true where [operator] = '" & Me.txtusername & "'"

thank you this was my next Q' work great
in the future i'm going to this with RFID chip so be here to help me :)
 

Users who are viewing this thread

Back
Top Bottom