Link to home
Start Free TrialLog in
Avatar of LeLeBrown
LeLeBrown

asked on

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
Avatar of plummet
plummet
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi Lisa

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

Thanks
John
Avatar of LeLeBrown
LeLeBrown

ASKER

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
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
ASKER CERTIFIED SOLUTION
Avatar of LeLeBrown
LeLeBrown

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No problem, you fixed it before I got back to my PC!
I had the statement incorrect and it was a easy fix.