Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append/Null Problem

Status
Not open for further replies.

Ninabunny

Programmer
Jul 24, 2000
70
US
I have a problem with the Append query I have generated...When I go to a brand new record it says it has nulls in the fields.&nbsp;&nbsp;How do I fix this?<br>Here is the code:<br>Private Sub Form_AfterUpdate()<br>&nbsp;&nbsp;&nbsp;&nbsp;If Me.PId = gvPId And _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me.Address = gvaddress And _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me.City = gvcity And _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me.State = gvstate And _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me.Country = gvcountry And _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me.Zip = gvzip Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Call Appendme<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>End Sub<br>Private Sub Form_Current()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;gvPId = Me.PId<br>&nbsp;&nbsp;&nbsp;&nbsp;gvaddress = Me.Address<br>&nbsp;&nbsp;&nbsp;&nbsp;gvcity = Me.City<br>&nbsp;&nbsp;&nbsp;&nbsp;gvstate = Me.State<br>&nbsp;&nbsp;&nbsp;&nbsp;gvcountry = Me.Country<br>&nbsp;&nbsp;&nbsp;&nbsp;gvzip = Me.Zip<br><br>End Sub<br>Option Compare Database<br>Public gvaddress As String<br>Public gvcity As String<br>Public gvstate As String<br>Public gvcountry As String<br>Public gvzip As String<br>Public gvPId As Integer<br><br>Public Function Appendme() As Boolean<br><br>&nbsp;&nbsp;&nbsp;&nbsp;'Appendme = False<br>&nbsp;&nbsp;&nbsp;&nbsp;'docmd.setwarnings false<br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.OpenQuery &quot;qryAppend&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;DoCmd.SetWarnings True<br>&nbsp;&nbsp;&nbsp;&nbsp;'Appendme = True<br><br>End Function<br><br>Public Function fungvaddress()<br>&nbsp;&nbsp;&nbsp;&nbsp;fungvaddress = gvaddress<br>End Function<br><br>Public Function fungvcountry()<br>&nbsp;&nbsp;&nbsp;&nbsp;fungvcountry = gvcountry<br>End Function<br><br>Public Function fungvzip()<br>&nbsp;&nbsp;&nbsp;&nbsp;fungvzip = gvzip<br>End Function<br><br>Public Function fungvcity()<br>&nbsp;&nbsp;&nbsp;&nbsp;fungvcity = gvcity<br>End Function<br><br>Public Function fungvstate()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fungvstate = gvstate<br>End Function<br><br>Public Function fungvPId()<br>&nbsp;&nbsp;&nbsp;&nbsp;fungvPId = gvPId<br>End Function<br><br>This is what I have and it appends according to the functions in the append query but when I start anew record it says I have a null problem.&nbsp;&nbsp;Any error coding or something like an if statement to fix this?<br>
 
It may be a timing issue, according to Access Help.<br><br>Creating a new record<br>When you move the focus to a new (blank) record on a form and then create a new record by typing in a control, the following sequence of events occurs:<br><br>Current (form) Þ Enter (control) Þ GotFocus (control) Þ BeforeInsert (form) Þ AfterInsert (form)<br><br>The BeforeUpdate and AfterUpdate events for the controls on the form and for the new record occur after the BeforeInsert event and before the AfterInsert event.<br><br><br>Personally, I stay away from the &quot;On Current&quot; event, it is not specific enough. I would put the logic you have in current in &quot;BEFORE&quot; update or &quot;BEFORE&quot; insert.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top