|
-
Nov 7th, 2007, 07:21 AM
#1
Thread Starter
Addicted Member
[RESOLVED] VBA Module help - Passing a form name.
Hey all, I want to use a few modules to save repetitive coding in a project:
such as:
Code:
Sub recordposition()
Select Case Me.Recordset.AbsolutePosition
Case 0
cmdnext.Visible = True
cmdprevious.Visible = False
Case Else
cmdnext.Visible = True
cmdprevious.Visible = True
End Select
End Sub
It crashes on the Me.recordset - how do I pass the form name over to the module?
Rich
Last edited by Bazzlad; Nov 8th, 2007 at 09:18 AM.
-
Nov 7th, 2007, 07:52 AM
#2
Re: VBA Module help - Passing a form name.
You don't want to pass the form name (as that would just be a string containing the name), you want to pass the form (which allows you to use the properties etc).
You would add/use the parameter like this:
Code:
Sub recordposition(theForm as Form)
Select Case theForm.Recordset.AbsolutePosition
Case 0
theForm.cmdnext.Visible = True
theForm.cmdprevious.Visible = False
...
..and pass the parameter like this:
Code:
recordposition Me
'or:
Call recordposition (Me)
-
Nov 7th, 2007, 08:58 AM
#3
Thread Starter
Addicted Member
Re: VBA Module help - Passing a form name.
You're a star Si, thank you!
-
Nov 7th, 2007, 10:46 AM
#4
Thread Starter
Addicted Member
Re: [RESOLVED] VBA Module help - Passing a form name.
You still here Si?
If so, how would I do the same, but reference a DIFFERENT form (not ME!)
call recordposition(Forms!frmmain) isn't working!!!
-
Nov 7th, 2007, 11:14 AM
#5
Thread Starter
Addicted Member
Re: [NEARLY RESOLVED] VBA Module help - Passing a form name.
Here's what I have
On the form calling it
Code:
Call addition(Me, Form_frmsalesbyadd.Form)
In the module
Code:
Sub addition(theform As Form, form2 As Form)
If Not theform.salesnumber.Value = vbNullString Then
Dim salenumber As String
salenumber = theform.salesnumber.Value
Else
salenumber = ""
End If
DoCmd.OpenForm form2
form2.txtreturn.Value = salenumber
For Each frm In Forms
If Not frm.Name = form2 Then
DoCmd.Close acForm, frm.Name
End If
Next frm
End Sub
-
Nov 7th, 2007, 01:06 PM
#6
Re: Help me! VBA Module help - Passing a form name.
Did it work for you or did you get errors?
-
Nov 7th, 2007, 01:51 PM
#7
Re: Help me! VBA Module help - Passing a form name.
Looks like you are doing this in Access?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 8th, 2007, 03:51 AM
#8
Thread Starter
Addicted Member
Re: Help me! VBA Module help - Passing a form name.
Yes I'm doing this in access,
and no it doesn't work.
The first bit works fine - it's when referencing the second form - it just doesn't work, I've tried:
[forms]![frmsalesbyadd]
[forms]![frmsalesbyadd].form
forms!frmsalesbyadd
forms_frmsalesbyadd
You name it, I've tried it, so what am I doing wrong?
-
Nov 8th, 2007, 09:18 AM
#9
Thread Starter
Addicted Member
Re: Help me! VBA Module help - Passing a form name.
DONE!
Both forms needed to be open as below:
Code:
Private Sub cmdsalesbyadd_Click()
DoCmd.OpenForm ("frmsalesbyadd")
Call addition(Me, [Forms]!frmsalesbyadd)
For Each frm In Forms
If Not frm.Name = "frmsalesbyadd" Then
DoCmd.Close acForm, frm.Name
End If
Next frm
End Sub
Code:
Sub addition(theform As Form, form2 As Form)
If Not theform.salesnumber.Value = vbNullString Then
Dim salenumber As String
salenumber = theform.salesnumber.Value
Else
salenumber = ""
End If
form2.txtreturn.Value = salenumber
End Sub
-
Nov 8th, 2007, 10:58 PM
#10
Re: [RESOLVED] VBA Module help - Passing a form name.
Yes, the form needs to be open first or it will not be contained in the [Forms] collection. When ever a form is opened Access adds the form to the Forms collection for reference as its in use.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|