David,
I would expect code in the OnOpen like:
If Me.OpenArgs & "" <> "" Then 'make sure there is OpenArgs
Me.[some control name].DefaultValue = Me.OpenArgs
End If
Regards,
Duane
From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of david.pratt@outlook.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Monday, February 13, 2017 7:00 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] VBA for Add New Record on 2-Click
Sent: Monday, February 13, 2017 7:00 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] VBA for Add New Record on 2-Click
OK, thanks.
Still not quite there but at least some improvement. Here is my OpenForm now:
DoCmd.OpenForm "frmSegmentsAndFeatures", acNormal, , , acFormAdd, acDialog, "ProjectID =" & cboSelectProject.Value
in the OnOpen Event for frmSegmentsAndFeatures I have:
me.cboProjectID.requery
txtSegmentNumber.setFocus
The SetFocus works fine, but the ProjectID field is not updating to the value in cboSelectProject.
However, if the frmSegmentsAndFeatures is already open, in either DesignView or FormView, then the ProjectField is properly filled with the value in cboSelectProject.. thus it is only in the Dialog mode that the ProjectID is not being properly set.
I tried moving the code to the OnCurrent and OnLoad events but neither of those helped.
'
'
---In MS_Access_Professionals@yahoogroups.com, <duanehookom@...> wrote :
David,
Congrats and exploring and trying something new!
If you open a form acDialog, the code will stop running until the form frmSegmentsAndFeatures is closed.
Since you seem to be comfortable with research on your own, check out "OpenArgs" which allows you to send values to the form being opened. Send the values you want to set and then have code in the On Open event of frmSegmentsAndFeatures which sets the default values of the controls.
Regards,
Duane
From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of david.pratt@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Sunday, February 12, 2017 11:10 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] VBA for Add New Record on 2-Click
Sent: Sunday, February 12, 2017 11:10 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] VBA for Add New Record on 2-Click
I am reading stuff and looking at internet stuff and watching YouTube videos trying to learn and get new ideas. I recently watched a YouTube video about Project Management. IN that video he used a form that I am trying to reproduce. the video talks about the information in the form, but not how to create the form, so I am trying on my own to reproduce the form as a learning method.
The form is unbound, has two combo boxes at the top; one for Company and one for Projects, both unbound, and has four list boxes. The form name is frmMainProjMgr. So at the top I have cboSelectCompany and cboSelectProject, with cboSelectProject query criteria based on the value of cboSelectCompany. No problem.
Under the two combo's are several list boxes. My first list box is based on a query of ProjectSegments table, which includes the foreign key ProjectID (with combo cboProjectID). The form's query criteria is based on the value of the unbound combo, cboSelectProject. I am trying to add new records to this table of ProjectSegments. I want to 2-click on the list box and bring up a form to create a new ProjectSegments record. The name of that form is frmSegmentsAndFeatures.
Also, when I bring up the form frmSegmentsAndFeatures to create a new ProjectSegment record, I would like the value in ProjectSegment.ProjectID to default to the value of cboSelectProject and I would like to set the focus on that form to the control named txtSegmentNumber. My VBA is not working and I need help please.
Here is what I have on the 2-click event for the list box:
Private Sub lstProjectSegments_DblClick(Cancel As Integer)
On Error GoTo lstProjectSegments_Click_Err
On Error GoTo lstProjectSegments_Click_Err
On Error Resume Next
DoCmd.OpenForm "frmSegmentsAndFeatures", acNormal, , , acFormAdd, acDialog
Forms!frmSegmentsAndFeatures.cboProjectID = Forms!frmMainProjMgr.cboSelectProjectID
Forms!frmSegmentsAndFeatures!txtSegmentNumber.SetFocus
If (Error <> 0) Then
Beep
MsgBox Error.Description, vbOKOnly, ""
End If
DoCmd.OpenForm "frmSegmentsAndFeatures", acNormal, , , acFormAdd, acDialog
Forms!frmSegmentsAndFeatures.cboProjectID = Forms!frmMainProjMgr.cboSelectProjectID
Forms!frmSegmentsAndFeatures!txtSegmentNumber.SetFocus
If (Error <> 0) Then
Beep
MsgBox Error.Description, vbOKOnly, ""
End If
lstProjectSegments_Click_Exit:
Exit Sub
lstProjectSegments_Click_Err:
MsgBox Error$
Resume lstProjectSegments_Click_Exit
End Sub
MsgBox Error$
Resume lstProjectSegments_Click_Exit
End Sub
__._,_.___
Posted by: Duane Hookom <duanehookom@hotmail.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (7) |
Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.
.
__,_._,___
Tidak ada komentar:
Posting Komentar