Opening a form with filtered details

mreference

Registered User.
Local time
Today, 16:02
Joined
Oct 4, 2010
Messages
137
I have an opening login form that takes the user to a form that displays their own personal details along with previous entries made on a timesheet form.

On this form, a user has the ability to open another form to log work carried out onto a timesheet.

What I would like to do, is when the button is clicked and it opens the timesheet entry form, is to only have that officers name displayed in the combobox rather than having to select it from the many names set up on the system.

This is not to save time, but to stop an officer accidently inputting time for another officer.

They both use the officerID field on the (Personal Details Form) and Combobox (cboOfficer) from the qryOfficer, if that helps :)

thanks in advance
 
Use the OpenArgs argument of the OpenForm Method.

This will fill in the field automatically for any record in that instance of the form.
 
Thanks for that, I have managed to pass the officerid across into the combo box and setfocus to the next field.

I also set Enabled to "No" and Locked to "Yes" so that they couldn't select another officer, however after submitting the timesheet, say they wanted to input another (they can only input one day at a time) my next question is:

Their name disappears from the combo box and because of the controls I have applied to it, they cannot reselect it, so therefore can I have their name repeated in the combo box until such time they close the form?
 
Last edited:
Opening a form with filtered details (anyone help?)

Is anyone able to help with my latest posting?
regards
 
I have built a similar function:
varAddAnotherCode = (MsgBox("Price code " & strPriceCode & " added successfully." _
& vbNewLine & "Would you like to add another Price Code?", vbYesNo, "New Price Codes."))

If varAddAnotherCode = vbYes Then
With Me
.txtPriceCode = ""
.cboClass = ""
.txtDescription = ""
.txtPriceCode.SetFocus
End With
Else
DoCmd.Close acForm, Me.Name

End If

As you can see, I provide a confirmation for a new price code and allow the user to add another. I then clear the fields rather than re-opening the form. Maybe you could employ a similar method of manipulating your fields. Please note I am using an unbound form for data entry.

The full code of the event is here:

Private Sub cmdCommit_Click()
Dim intPC_ID As Integer
Dim strPriceCode, strClass As String
Dim strSQL_AddPriceCode As String
Dim varDescription As Variant
Dim strErrMessage As String
Dim blnError As Boolean
Dim varAddAnotherCode As Variant

intPC_ID = DMax("PC_ID", "PriceCodes") + 1
blnError = False
strErrMessage = ""


With Me
strPriceCode = Nz(.txtPriceCode, "Error")
strClass = Nz(.cboClass, "Error")
varDescription = Nz(.txtDescription, "Error")
End With

If Len(strPriceCode) > 50 Then
blnError = True
strErrMessage = "The Price Code must be fifty characters or less, including spaces"
ElseIf strPriceCode = "Error" Then
blnError = True
strErrMessage = "Please enter the Price Code"
ElseIf Nz(DLookup("PC_ID", "PriceCodes", "[PriceCode] = '" & strPriceCode & "' "), 0) > 0 Then
'Price Code already exists
blnError = True
strErrMessage = "This Price Code already exists, please try again."
End If

If strClass = "Error" Then
blnError = True

If Len(strErrMessage) < 1 Then
strErrMessage = "Please select a class from the drop down box."
Else
strErrMessage = strErrMessage & vbNewLine & "Please select a class from the drop down box."
End If

End If


If varDescription = "Error" Then
blnError = True

If Len(strErrMessage) < 1 Then
strErrMessage = "Please enter a description for this Price Code."
Else
strErrMessage = strErrMessage & vbNewLine & "Please enter a description for this Price Code."
End If
Else
Replace varDescription, Chr(34), ""
End If


If blnError = True Then
'present error messages
MsgBox strErrMessage, vbOKOnly, "Error."
Else
strSQL_AddPriceCode = "INSERT INTO PriceCodes (PC_ID,PriceCode,Class,Description)" _
& "SELECT " & intPC_ID & ", '" & strPriceCode & "', '" & strClass & "', " & Chr(34) & varDescription & Chr(34)

'DoCmd.OpenForm "sqltester"
'Form_sqltester.txtSQL = strSQL_AddPriceCode

DoCmd.SetWarnings False
DoCmd.RunSQL strSQL_AddPriceCode
DoCmd.SetWarnings True

varAddAnotherCode = (MsgBox("Price code " & strPriceCode & " added successfully." _
& vbNewLine & "Would you like to add another Price Code?", vbYesNo, "New Price Codes."))

If varAddAnotherCode = vbYes Then
With Me
.txtPriceCode = ""
.cboClass = ""
.txtDescription = ""
.txtPriceCode.SetFocus
End With
Else
DoCmd.Close acForm, Me.Name

End If

End If

End Sub
 
Thank you, worked fine, just couldn't clear my sub forms records, but when I tab from the parent form into the subform to enter details, the previous record disappears.

many thanks
 

Users who are viewing this thread

Back
Top Bottom