• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

MS Access forms - passing data

I have two forms in Access 2007. I call one form using docmd and pass a variable from the list box on the first form. I then need to use that data in the second form. I have tried using it in the open and load events of the form but get invalid use of null. When I navigate to the form without putting this statement in, I see the variable value that I pass on the form. Why can't I use it in code when the form first loads/opens?

Thanks
Lisa
0
LeLeBrown
Asked:
LeLeBrown
  • 4
  • 2
1 Solution
 
plummetCommented:
Hi Lisa

Could you post the code that's giving the error?

Thanks
John
0
 
LeLeBrownAuthor Commented:
Private Sub Form_Open(Cancel As Integer)
Dim cd As DAO.Database
Dim rs As DAO.Recordset
Dim strSql As String
Dim GrantNo As String


GrantNo = Me.txtGrantLevelGrantNumber <========= Error here because the form text field has not been populated yet.


   Set cd = CurrentDb
   strSql = "select * from GrantNumbersWithRemovalIndicator where GrantNumber = '" & GrantNo & " ' "
   Set rs = cd.OpenRecordset(strSql)
   Me.txtGrantLevelComments.Value = rs!Comments
End Sub
0
 
LeLeBrownAuthor Commented:
forgot to post code to go to second form. it is just too lines of code:

Private Sub cmdSelect_Click()

DoCmd.OpenForm "GrantLevelCommentsRemovals"
Forms!GrantLevelCommentsRemovals!txtGrantLevelGrantNumber = Me.List2.Value
End Sub
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LeLeBrownAuthor Commented:
Nevermind. I just set GrantNo to the first form's data. I tried doing it before but my statement must have been incorrect. I did the below and it worked:

GrantNo = Forms("GrantListForm").List2.Value
0
 
plummetCommented:
No problem, you fixed it before I got back to my PC!
0
 
LeLeBrownAuthor Commented:
I had the statement incorrect and it was a easy fix.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now