• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • 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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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