deweysanchez
New member
- Local time
- Today, 03:01
- Joined
- Aug 10, 2009
- Messages
- 5
Hi,
I have been trying to use queries to retrieve data from other forms and have failed miserably. I have therefore cobbled together the following code to do the job instead (see below). My question is: Would it simply the code if I were to use quieries instead? or is it worth changing it to using quieries and if so could someone please help with the coding?
Hugs n' Stuff
Dewey
Private Sub Form_Open(Cancel As Integer)
Dim stDeptDoc As String
Dim stStaffDoc As String
Dim stJobDoc As String
Dim stDeptlink As String
Dim stStaffLink As String
Dim stJobLink As String
Dim DeptN1 As String
Dim JobN1 As String
Dim DeptN2 As String
Dim JobN3 As String
Dim UserN As String
Me!UserName = CurrentUser
stStaffDoc = "STAFFLISTForm"
stStaffLink = "[StaffMember]=" & "'" & Me![UserName] & "'"
DoCmd.OpenForm stStaffDoc, , , stStaffLink, acFormReadOnly, acHidden
DeptN1 = Forms!STAFFLISTForm!Department
JobN1 = Forms!STAFFLISTForm!JobTitle
UserN = Forms!STAFFLISTForm!ID
DoCmd.Close acForm, "STAFFLISTForm", acSaveNo
On Error GoTo DeptError
stDeptDoc = "DEPARTMENTForm"
stDeptlink = "[ID]=" & DeptN1
DoCmd.OpenForm stDeptDoc, acNormal, , stDeptlink, acFormReadOnly, acHidden
DeptN2 = Forms!DEPARTMENTForm!Department
DoCmd.Close acForm, "DEPARTMENTForm", acSaveNo
On Error GoTo JobError
stJobDoc = "JOBTITLEForm"
stJobLink = "[ID]=" & JobN1
DoCmd.OpenForm stJobDoc, , , stJobLink, acFormReadOnly, acHidden
JobN2 = Forms!JOBTITLEForm!JobTitle
DoCmd.Close acForm, "JOBTITLEForm", acSaveNo
Me!JobName = JobN2
Me!DeptName = DeptN2
Exit Sub
DeptError:
If Err.Number = 2427 Then
DeptN2 = "No Department"
Resume Next
End If
JobError:
If Err.Number = 2427 Then
JobN2 = "No Job Title"
Resume Next
End If
End Sub
I have been trying to use queries to retrieve data from other forms and have failed miserably. I have therefore cobbled together the following code to do the job instead (see below). My question is: Would it simply the code if I were to use quieries instead? or is it worth changing it to using quieries and if so could someone please help with the coding?
Hugs n' Stuff
Dewey
Private Sub Form_Open(Cancel As Integer)
Dim stDeptDoc As String
Dim stStaffDoc As String
Dim stJobDoc As String
Dim stDeptlink As String
Dim stStaffLink As String
Dim stJobLink As String
Dim DeptN1 As String
Dim JobN1 As String
Dim DeptN2 As String
Dim JobN3 As String
Dim UserN As String
Me!UserName = CurrentUser
stStaffDoc = "STAFFLISTForm"
stStaffLink = "[StaffMember]=" & "'" & Me![UserName] & "'"
DoCmd.OpenForm stStaffDoc, , , stStaffLink, acFormReadOnly, acHidden
DeptN1 = Forms!STAFFLISTForm!Department
JobN1 = Forms!STAFFLISTForm!JobTitle
UserN = Forms!STAFFLISTForm!ID
DoCmd.Close acForm, "STAFFLISTForm", acSaveNo
On Error GoTo DeptError
stDeptDoc = "DEPARTMENTForm"
stDeptlink = "[ID]=" & DeptN1
DoCmd.OpenForm stDeptDoc, acNormal, , stDeptlink, acFormReadOnly, acHidden
DeptN2 = Forms!DEPARTMENTForm!Department
DoCmd.Close acForm, "DEPARTMENTForm", acSaveNo
On Error GoTo JobError
stJobDoc = "JOBTITLEForm"
stJobLink = "[ID]=" & JobN1
DoCmd.OpenForm stJobDoc, , , stJobLink, acFormReadOnly, acHidden
JobN2 = Forms!JOBTITLEForm!JobTitle
DoCmd.Close acForm, "JOBTITLEForm", acSaveNo
Me!JobName = JobN2
Me!DeptName = DeptN2
Exit Sub
DeptError:
If Err.Number = 2427 Then
DeptN2 = "No Department"
Resume Next
End If
JobError:
If Err.Number = 2427 Then
JobN2 = "No Job Title"
Resume Next
End If
End Sub