Pass data from one form to another (1 Viewer)

Louise Wallen

Registered User.
Local time
Today, 05:32
Joined
Jun 20, 2017
Messages
17
I have used some queries, infact I think I have used way too many in other areas, but in this case I haven't
 

RuralGuy

AWF VIP
Local time
Today, 06:32
Joined
Jul 2, 2005
Messages
13,826
Queries take up very little space in a db as they are just the SQL and some strategy. Let's modify the Load Event code.
 

RuralGuy

AWF VIP
Local time
Today, 06:32
Joined
Jul 2, 2005
Messages
13,826
Code:
Private Sub Form_Load()
Dim strOpenArgs() As String

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

RuralGuy

AWF VIP
Local time
Today, 06:32
Joined
Jul 2, 2005
Messages
13,826
BTW, does the ComboBox have a ControlSource (Is it Bound)?
 

Louise Wallen

Registered User.
Local time
Today, 05:32
Joined
Jun 20, 2017
Messages
17
RuralGuy you are a genius!!!! It worked!!!! Thank you sooo much
I don't know whether it is bound... I don't know what that means :) I think I have been a bit ambitious with this database lol... it's getting there slowly though!
The next step is to update the comments shown on form one with the newly added comment, but I shall have a go and see.
I have to go home from work now, but that you so much for taking the time out of your day to offer me some friendly advice.
It means a lot and I am very grateful. I'm sure as you have done a good deed today in helping me that your day will be truly wonderful :)
 

RuralGuy

AWF VIP
Local time
Today, 06:32
Joined
Jul 2, 2005
Messages
13,826
Check back tomorrow. We need to cover a couple of additional things. Go home for now and I'll leave the posts for you to read later.
 

RuralGuy

AWF VIP
Local time
Today, 06:32
Joined
Jul 2, 2005
Messages
13,826
For the record, bound Control means it has a ControlSource, bound Form means it has a RecordSource. Basically when you change the value it is changing the value in a table somewhere. Unbound, that is not the case unless you do the changing yourself.
If the 1st form is displaying the "Comments" that you changed with the 2nd form, there is a way to get them to show up on form #1 automatically. Just post back and we'll do it. BTW, did you decide to change the ComboBox into a TextBox? I think it would be a good idea. Just my $0.02 :)
 

RuralGuy

AWF VIP
Local time
Today, 06:32
Joined
Jul 2, 2005
Messages
13,826
As you gain experience in MS Access you will discover other methods to pass values between forms. I prefer the one I used because it doed not require the form to know anything about who launched it. It is more modular that way. :)
 

Dirtrider929

Registered User.
Local time
Today, 06:32
Joined
Nov 12, 2013
Messages
32
I have one other step I would like to know how to code in reference to this topic. This worked great for what I needed with one caveat, it allows duplicate records to be created for the same [Offer_ID] in my table.

How can I get it to look for an existing record using [Offer_ID] and open the record should it exist already or create a new record if it does not?

On Click On Form 1

On Error GoTo Err_cmdOpen_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSLR_ChainInvoice_Detail"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me.OFFER_ID

Exit_cmdOpen_Click:
Exit Sub

Err_cmdOpen_Click:
MsgBox Err.Description
Resume Exit_cmdOpen_Click

End Sub

Form Load Event on Form 2

Private Sub Form_Load()
Dim strOpenArgs() As String

If Not IsNull(Me.OpenArgs) Then
strOpenArgs = Split(Me.OpenArgs, ";")
Me.OfferID = strOpenArgs(0)

Else
' .. Do something else
End If

End Sub
 

Morpheus16

New member
Local time
Today, 20:32
Joined
Oct 5, 2020
Messages
1
Hello, I'm getting a Run time error while running the code, says Microsoft Access couldn't print your object.

In my case I've applied it on a report where a button is available for certificate printing. This report returns a list of assets assigned on a particular employee. The OpenArgs on the Do.cmd can already get the ID of the button where it is being clicked. However the stlinkCriteria returns 0, maybe this is causing me the problem, please Help, I'm really stuck. thank you so much in advance.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:32
Joined
May 7, 2009
Messages
19,231
can you post the code you have on opening the report.
you only need to provide the strLinkCriteria:

strLinkCriteria = "[ID] = " & ME!ID
docmd.OpenReport ReportName:="yourReport",WhereCondition:=strLinkCriteria
 

Users who are viewing this thread

Top Bottom