UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
> Syntax For Passing And Using Variables In Subroutines    
 
   
muse43
post Aug 15 2016, 02:14 PM
Post#1



Posts: 93
Joined: 21-January 13



Hi!

I am working on programming my first form that will point to a sub in an outside module using variables. (i.e. instead of writing the code on the form's VBA sheet - or object- I am writing it in a new module and calling it from the form's code).

I use the code below a lot so I thought it would be a good one to start with (for learning). In this case, it is used to open a Clientdetails Form from a main Form but once opened, I want the user to still be able to navigate to other clients while staying on the client details form. The code itself works fine but when trying to put it in a separate module and use variables, I am having trouble.

Here is the code so far:

On the form's page :

Private Sub GoToClientDetails_Click()

OpenToBookmarkM.OpenToBookmark "ClientDetailsF", Me.ID

End Sub

On the module page (the actual routine):

Sub OpenToBookmark(FormName As String, CurrentID As Integer)

DoCmd.OpenForm FormName, , , "[ID]=" & CurrentID

Dim intID As Integer
Dim rs As Object
intID = Forms!ClientDetailsF.ID
Forms!ClientDetailsF.FilterOn = False
Set rs = Forms!ClientDetailsF.RecordsetClone
With rs
.FindFirst "[ID]=" & intID
Forms!ClientDetailsF.Bookmark = .Bookmark
End With
rs.Close

End Sub


As it stands it works. So far I've only used the variables to open the new form (DoCmd.OpenForm FormName, , , "[ID]=" & CurrentID).

Next, I want to replace intID = Forms!ClientDetailsF.ID with intID = Forms!FormName.ID

This doesn't work though. I believe it is because FormName is a string and I can't just stick it in there. I've tried a few other things but nothing seems to work and I don't know where to go next. How to replace all instances of "ClientDetailsF" in my routine so that I can use it for any other form as well in the future?

Any help on this would be very much appreciated.

Thanks!
Go to the top of the page
 

Posts in this topic



Custom Search


RSSSearch   Top   Lo-Fi    25th January 2020 - 05:31 AM