Passing data between forms OpenArgs? (1 Viewer)

tucker61

Registered User.
Local time
Today, 11:50
Joined
Jan 13, 2008
Messages
321
Hi all, i need some help,

Firstly - i tried to zip a copy of my database so i can upload, but the smallest i can get this is 12mb, so unfortunately i am unable to upload.

I have 2 forms - FrmMain and Frminspection.

My main form (FrmMain) assigns a job number to the request, and then when the product is inspected, i want to pass this job number to the FrmInspection, in order to link the records together.

My issue is all around passing the job number over to the FrmInspection page.

I have coded this so that when i click on the tab controls, if the Job number is blank, to bring the job number from my main form, but by coding it like this, when i click through the tabs, i get a blank record created (Which i don't want)

I have tried with OpenArgs, but did not manage to get this working.

Can anyone advise as this has been happening for sometime.

I have the following code on my on Enter Even of my tab on the Frminspection
Code:
Private Sub subforminitialinspection_Enter()
If IsNull(Forms!FrmInspection.tbjobid) Or Forms!FrmInspection.tbjobid = "" Then
Forms!FrmInspection.Job_ID = Forms!frmMain.Job_ID
End If
End Sub

and the following to pass the OpenArgs Field

Code:
DoCmd.OpenForm "frmInspection", , , , , , Job_ID

and the following to retrieve the OpenArgs data

Code:
Job_id = Forms!FrmInspection.OpenArgs
 

GPGeorge

Grover Park George
Local time
Today, 11:50
Joined
Nov 25, 2004
Messages
1,776
Often, a more detailed description of what actually happened is better than statements like "I have tried with OpenArgs, but did not manage to get this working." In other words, what did you expect? What DID happen instead? Descriptions of that sort make it more likely someone can help identify the REASON "it didn't work".
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:50
Joined
May 21, 2018
Messages
8,463
Firstly - i tried to zip a copy of my database so i can upload, but the smallest i can get this is 12mb, so unfortunately i am unable to upload.
Do you have more than a couple 100k records, stored images, or attachments. If not I bet if you compact and repair you db it will drastically reduce below 12mg.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:50
Joined
May 21, 2018
Messages
8,463
My issue is all around passing the job number over to the FrmInspection page.
The should be linked as Mainform to subform.
 

tucker61

Registered User.
Local time
Today, 11:50
Joined
Jan 13, 2008
Messages
321
Do you have more than a couple 100k records, stored images, or attachments. If not I bet if you compact and repair you db it will drastically reduce below 12mg.
that's what i dont understand, i have 3 tables with 3 records , and 3 forms, and i cant make it any smaller.

With the Ref to OpenArgs, i think i have done it right, but i think the issue is more around that i have the code on the on enter field, I have tried on before update, but one of my fields is a primary key and indexed, so cant be left blank. I am at a loss.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:50
Joined
May 21, 2018
Messages
8,463
that's what i dont understand, i have 3 tables with 3 records , and 3 forms, and i cant make it any smaller.
You might want to create a new db and import your objects into it. See if that helps. Make sure to compact and repair the database.
I see you did that already.
 

tucker61

Registered User.
Local time
Today, 11:50
Joined
Jan 13, 2008
Messages
321
Imported into New DB and now only 1.5mb
 

Attachments

  • New Microsoft Access Database (2).zip
    114.1 KB · Views: 201

tucker61

Registered User.
Local time
Today, 11:50
Joined
Jan 13, 2008
Messages
321
Ok, i have managed to get the OpenArgs data to pass to the 2nd form using the code posted by Badly Bob in another post.

I still have a issue that it creates a new record with just the job number stored in the table.
 

tucker61

Registered User.
Local time
Today, 11:50
Joined
Jan 13, 2008
Messages
321
Latest version - OpenArgs working, but creating blank record, just storing the Job number - am i doing something wrong or do i need to build in to delete the blank records ?
 

Attachments

  • New Microsoft Access Database (3).zip
    111.3 KB · Views: 243

Gasman

Enthusiastic Amateur
Local time
Today, 18:50
Joined
Sep 21, 2011
Messages
14,046
I get this as soon as I open the DB? :(

1643912942018.png

And I get this when I click the button?

1643913368739.png


All your data appears to be on a subform anyway?
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 18:50
Joined
Sep 21, 2011
Messages
14,046
How is anyone meant to use this?
When I try to select data from the subform I get
1643913995579.png
 

tucker61

Registered User.
Local time
Today, 11:50
Joined
Jan 13, 2008
Messages
321
updated - removed the code form the combo boxes
 

Attachments

  • New Microsoft Access Database.accdb
    1.4 MB · Views: 274

Gasman

Enthusiastic Amateur
Local time
Today, 18:50
Joined
Sep 21, 2011
Messages
14,046
Well I seem to be able to add records?
I would also be passing in the JobID as a filter, so as to see what was previously created?
 

Attachments

  • New Microsoft Access Database.accdb
    1.4 MB · Views: 250

tucker61

Registered User.
Local time
Today, 11:50
Joined
Jan 13, 2008
Messages
321
the issue is not so much in adding a record, if you delete all the data in the tblmeasures table, and then go on to FrmInspection, it creates a new record - i think this is due to the primary key, and the job number being stored. How do i deal with these false records ?
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:50
Joined
Sep 21, 2011
Messages
14,046
I used to only set the data from openargs if it was a new record. If records already existed then using that filter option I mentioned, it would just show those. Then I would add manually.
So do not dirty the record until you need to, or validate in the beforeupdate event to stop the new record.
 

tucker61

Registered User.
Local time
Today, 11:50
Joined
Jan 13, 2008
Messages
321
I used to only set the data from openargs if it was a new record. If records already existed then using that filter option I mentioned, it would just show those. Then I would add manually.
So do not dirty the record until you need to, or validate in the beforeupdate event to stop the new record.
That sounds like the bit i am struggling on, so would i start with

Code:
If NewRecord Then
    If Not IsNull(Me.OpenArgs) Then
      strOpenArgs = Split(Me.OpenArgs, ";")
      Me.TbJobId = strOpenArgs(0)
    '.. If there were more arguments
    '  Me.txtAnotherTextBox = strOpenArgs(1)
    Else
    ' .. Do something else
    End If
Else
End If
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:50
Joined
Sep 21, 2011
Messages
14,046
I used Me.NewRecord.
No need for the Else paths in your above code either?
 

tucker61

Registered User.
Local time
Today, 11:50
Joined
Jan 13, 2008
Messages
321
Code changes to the below.
Code:
If Me.NewRecord Then
    If Not IsNull(Me.OpenArgs) Then
      strOpenArgs = Split(Me.OpenArgs, ";")
      Me.TbJobId = strOpenArgs(0)
    End If
End If

Not sure i understand what you mean by the above, can you explain in more detail how to do this.
So do not dirty the record until you need to, or validate in the beforeupdate event to stop the new record.
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:50
Joined
Sep 21, 2011
Messages
14,046
As soon as you set JobID, you dirtied the record, and access will automatically save it, if not prevented by validation. The beforeupdate event of the form, is the last place to stop that save happening, unless the data is to your satisfaction.
 

Users who are viewing this thread

Top Bottom