VBA Help with my code (1 Viewer)

snirben

Registered User.
Local time
Today, 03:57
Joined
Nov 26, 2016
Messages
33
Hi Guys I have two forms.
one form is a form to create in order with OrderID
and second form is to edit the order with more details and stuff
so i made a button in the first form to save the recored and open the same OrderID in the second form to edit, but when it opens i want to move to aouter record using the combo box i have, it just stuck on the first record i open

this is my code from the first form.

Code:
Private Sub Command130_Click()
DoCmd.RunCommand acCmdSaveRecord
Dim strDocName As String
Dim strWhere As String
    strDocName = "OpenActionMihrazFormEdit"
    strWhere = "[ActionNumber]=" & Me!ActionNumber
   DoCmd.OpenForm strDocName, acNormal, , strWhere
   DoCmd.Close acForm, "ActionMihrazForm", acSaveYes

End Sub
 

boerbende

Ben
Local time
Today, 12:57
Joined
Feb 10, 2013
Messages
339
What I understand is that you open a form with a where string, so reducing the number of records in the recordsource of this form by setting the filter.

your wherestr has only one action number, so this will be the only one "visible". You can select whetever else you want, the form cannot show it because it does not have it
You can maybe create a button in your form where you "release" the filter.

Ben
 

missinglinq

AWF VIP
Local time
Today, 06:57
Joined
Jun 20, 2003
Messages
6,423
As Ben said, when you open a Form filtering it, like you have, it essentially only has one Record in its Recordset...and hence, cannot move to other Records! To do what you want, you'll need to use a different approach, using the OpenArgs parameter to pass the ActionNumber to the secondary Form (OpenActionMihrazFormEdit). So, in the primary (ActionMihrazForm) Form:

Code:
Private Sub Command130_Click()

Dim strDocName As String

DoCmd.RunCommand acCmdSaveRecord

  strDocName = "OpenActionMihrazFormEdit"
   
  DoCmd.OpenForm strDocName, acNormal, , , , , Me.ActionNumber
   
  DoCmd.Close acForm, "ActionMihrazForm", acSaveYes

End Sub
Then, in the secondary (OpenActionMihrazFormEdit) Form:
Code:
Private Sub Form_Load()

Dim rst As DAO.Recordset

If Not IsNull(Me.OpenArgs) Then
 
 Set rst = Me.RecordsetClone
 
 rst.FindFirst "[ActionNumber] = " & Me.OpenArgs 

  If Not rst.NoMatch Then
      Me.Bookmark = rst.Bookmark
   Else
     DoCmd.GoToRecord , , acNewRec
     Me.ActionNumber =  Me.OpenArgs
   End If

rst.Close

Set rst = Nothing

End If

End Sub
This will check to see if an OpenArgs has been passed, when the Form is opened, and if so, will look for a Record containing that ActionNumber; if one is found, Access will move to that Record. You will later be able to move to other Records in the Form, as well.

If a matching Record is not found, you will be moved to a New Record...and the ActionNumber will be filled in with the passed ActionNumber.

BTW, the parameter in red

DoCmd.Close acForm, "ActionMihrazForm", acSaveYes

isn't doing what you think itis, i.e. saving data! That is used to save any Design Changes that have been made to the Form...not a factor, here.

Linq ;0)>
 

snirben

Registered User.
Local time
Today, 03:57
Joined
Nov 26, 2016
Messages
33
Wow, thank you.
how can I close the First form?
Just DoCmd. Close acForm, "ActionMihrazForm"?
 

missinglinq

AWF VIP
Local time
Today, 06:57
Joined
Jun 20, 2003
Messages
6,423
All you need is

DoCmd.Close acForm, "ActionMihrazForm"

Good luck with your project!

Linq ;0)>
 

Users who are viewing this thread

Top Bottom