How to code for a form by using two buttons on other form

venu_resoju

Registered User.
Local time
Today, 13:59
Joined
Dec 29, 2010
Messages
130
Hai Friends..

I have a form "PayrollCreation" which contain two text boxes named "txtDaysWorked" and "PH".
I have another form "Payroll" which contain two buttons named "PayrollbyDailyAttendance" and "PayrollbyMonthlyAttendance".I have given a code for these two buttons is as below.

Private Sub PayrollbyMonthlyAttendance_Click()
DoCmd.OpenForm "PayrollCreation"
End Sub


Private Sub PayrollbyDailyAttendance_Click()
DoCmd.OpenForm "PayrollCreation"
EndSub


but when I click "PayrollbyDailyAttendance", "txtDaysWorked= Dlookup("Somthing")" and "PH=Dlookup("Something)".

when I click "PayrollbyMonthlyAttendance", "txtDaysWorked= "" or 0" and "PH="" or 0".

how can I do this. Please anybody give me any idea...
Thanks in advance..
 
The OpenForm command has a OpenArgs parameter. With this parameter you can put anything in it. So to give you an example of how to solve your problem:
Code:
Private Sub [COLOR=DarkGreen]PayrollbyMonthlyAttendance[/COLOR]_Click()
     DoCmd.OpenForm "[COLOR=Red]PayrollCreation[/COLOR]", , , , , , "monthly"
End Sub
In your form's Load event:
Code:
Select Case Nz(Me.OpenArgs, vbNullString)
    Case "monthly"
        Me.txtDaysWorked = DLookup(something)
    Case "daily"

    Case Else
        ' do nothing
End Select
You can also put code in the Control Source of txtDaysWorked:
Code:
=IIF([OpenArgs] = "monthly", DLookup(something), 0)
 
Hai vbaInet..
Thanks for your reply.

I have use your code but not working....I am here with attache my DB. Please find it.

Thanking You.....
 

Attachments

I don't remember asking to see your db ;)

What is the problem? Is it throwing some errors?
 
I have given the code on form_Load event of "PayrollCreation" form is as below
Code:
[COLOR=Blue][COLOR=Black]Private Sub Form_Load()
Select Case Nz(Me.OpenArgs, vbNullString)
    Case "Daily"[/COLOR]
        [COLOR=Red]Me.txtNoofDaysWorked.Value[/COLOR] = [COLOR=Black]DCount("[EmpID]", "Attendance", "[EmpID]='" & [cboEmpName] & "' AND [AttendanceMonth]='" & [cboMonth] & "' AND [AttendanceYear]='" & [cboYear] & "' AND [AttendanceStatus]='" & "Present" & "'")
    Case "Monthly"[/COLOR]
        [COLOR=Red]Me.txtNoofDaysWorked.Value[/COLOR] =[COLOR=Black] Null[/COLOR]
    
[COLOR=Black]End Select
End Sub[/COLOR][/COLOR]
and on click event of "PayrollCreationbyDailyAttendance" and "PayrollCreationbyMonthlyAttendance" buttons on "Payroll" form are as given below.

Code:
[COLOR=Blue][COLOR=Black]Private Sub[/COLOR][COLOR=Red]PayrollCreationbyDailyAttenance[/COLOR][COLOR=Black]_Click()[/COLOR]
     [COLOR=Black]DoCmd.OpenForm "PayrollCreation", , , , , , "Daily"
End Sub[/COLOR]
[/COLOR]
Code:
[COLOR=Blue][COLOR=Black]Private Sub[/COLOR] [COLOR=Red]PayrollCreationbyMonthlyAttenance[/COLOR][COLOR=Black]_Click()[/COLOR]
     [COLOR=Black]DoCmd.OpenForm "PayrollCreation", , , , , , "Monthly"
End Sub[/COLOR]
[/COLOR]
but I am not get these results as ..when I click the "PayrollCreationbyDailyAttenance" button on "Payroll" form
Code:
[COLOR=Blue][COLOR=Red]Me.txtNoofDaysWorked.Value[/COLOR] = [COLOR=Black]DCount("[EmpID]", "Attendance", "[EmpID]='" & [cboEmpName] & "' AND [AttendanceMonth]='" & [cboMonth] & "' AND [AttendanceYear]='" & [cboYear] & "' AND [AttendanceStatus]='" & "Present" & "'")   [/COLOR]
[/COLOR]



and
when I click the "PayrollCreationbyMonthlyAttenance" button on "Payroll" form
Code:
Me.txtNoofDaysWorked.Value = Null


Please tell me anything wrong with me...
 
Last edited:
thank you for your suggestion...
How to get bound the form and controls?

please tell me in brief.

thank you
 
Hai...

I have tested the above code, it is working fine eve the text box is unbound...

but I want to get the result after selection of "cboEmpName" combo box on "PayrolCreation" form, this thing is not working.

Please see my attached DB and get my exact problem...
Thanking you sir..
 

Attachments

Last edited:
Like I previously mentioned, I don't want to see your db unless I ask for it. :)

Could you please make up your mind on what you want. In your first post you said you want the result when the form loads -->
but when I click "PayrollbyDailyAttendance", "txtDaysWorked= Dlookup("Somthing")" and "PH=Dlookup("Something)".

when I click "PayrollbyMonthlyAttendance", "txtDaysWorked= "" or 0" and "PH="" or 0".
... but now you are saying you actually want it when cboEmpName is clicked -->
but I want to get the result after selection of "cboEmpName" combo box on "PayrolCreation" form, this thing is not working.
:confused:
 
Hai....vbaInet..

you are right..

actually I didn't know about this thing before I put the code. I absorbed this thing after putting your code that's why I am asking you.

but problem is still the same. please see my attached DB and give me some ideas and suggestions to solve this problem.




Hai raghuprabhu.....

Thanks for your reply..

I have learned something from your attached DB, but my problem is not solved..please see my attached DB and give me some advise.

Thanks in advance
 
Venu,

Further to vbaInet's request, could you please tell us exactly what is the problem that you want help/assistance with? Sending a database and asking people to
Please see my attached DB and get my exact problem...
and
please see my attached DB and give me some ideas and suggestions to solve this problem.
is not very efficient in helping you get assistance.
 
Thank you jdraw...

I have given the code on form_Load event of "PayrollCreation" form is as below

Code:
Private Sub Form_Load()
Select Case Nz(Me.OpenArgs, vbNullString)
    Case "[COLOR="Red"]Daily[/COLOR]"
        [COLOR="blue"]Me.txtNoofDaysWorked.Value = DCount("[EmpID]", "Attendance", "[EmpID]='" & [cboEmpName] & "' AND [AttendanceMonth]='" & [cboMonth] & "' AND [AttendanceYear]='" & [cboYear] & "' AND [AttendanceStatus]='" & "Present" & "'")[/COLOR]
    Case "[COLOR="Red"]Monthly[/COLOR]"
        [COLOR="blue"]Me.txtNoofDaysWorked.Value = 0[/COLOR]
    
End Select
End Sub

'and

on click event of "PayrollCreationbyDailyAttendance" and "PayrollCreationbyMonthlyAttendance" buttons on "Payroll" form are as given below.

Code:
Private SubPayrollCreationbyDailyAttenance_Click()
     [COLOR="blue"]DoCmd.OpenForm "PayrollCreation", , , , , , "[COLOR="red"]Daily[/COLOR]"[/COLOR]
End Sub

[COLOR="green"]'and[/COLOR]

Private Sub PayrollCreationbyMonthlyAttenance_Click()
     [COLOR="Blue"]DoCmd.OpenForm "PayrollCreation", , , , , , "[COLOR="red"]Monthly[/COLOR]"[/COLOR]
End Sub


but I have 3 combo boxes named "cboEmpName", "cboMonth", "cboyear" on the form "PayrollCreation", the result will get on text box named "txtNoofDaysWorked" when I select the combo box.


as per the above coding...the "PayrollCreation" form is opening by clicking the "PayrollCreationbyDailyAttendance" Button.but the text box "txtNoofDaysWorked" is not getting Requerying the result by combo boxes.


Please see my attached DB and get my exact problem...
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom