Populating a sub form with a value

andrewhoddie

Board Regular
Joined
Dec 21, 2008
Messages
114
Hi all

I am using Access 2016 and an ODBC link to an SQL Database.

I have a form called "Search" which returns values into two sub forms ServiceUsersSearchList for current clients and TerminatedSericUsersSearch for former clients.

The results show ClientID, Address1, Address2, Postcode from table dbo_Voids the user clicks on the row and clicks on AddRent button.

This opens up a form called Rents where there is a field called ClientID from table dbo_rents, The two clientIDs are linked. What I would like is for the ClientID from the search to prepopulate on the Rents form.

I am using the following code:

Private Sub AddRent_Click()
On Error GoTo Err_AddRent_Click

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Rents"
stLinkCriteria = "[ClientID]=" & Me![ClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria


Exit_AddRent_Click:
Exit Sub
Err_AddRent_Click:
MsgBox Err.Description
Resume Exit_AddRent_Click


End Sub

Any help greatly appreciated.
thanks
Andrew
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I do it with OpenArgs

Calling form button
Code:
Private Sub cmdProgress_Click()
DoCmd.OpenForm "frmProgress", , , "CadetIDFK=" & Me.CadetID, , acDialog, Me.CadetID
End Sub

Called Form
Code:
Private Sub Form_Current()
If Me.NewRecord Then
    Me.CadetIDFK = Me.OpenArgs
End If
End Sub

So if records exists for the ID, I just get to see them. If none exist then the ID is populated correctly for the new record

HTH
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top