form load operation isnt working

R

reservedbcreater

Private Sub Form_Load()

Dim strNextNumber As String

strNextNumber = Nz(DMax("ID", "General Housing Survey"), 0) + 1

strNextNumber = Me.ID

End Sub

?????
i want it to read the General Housing Table ID field and get the highest
number and then increment it by 1 and then fill in the ID field
automatically on the form with the new number opon it opening
 
R

reservedbcreater

this doesnt work either



Private Sub Form_Load()

Dim strDocName As String
Dim strNextNumber As String

strDocName = "General Housing Survey"
strNextNumber = Nz(DMax("ID", "General Housing Survey"), 0) + 1

strNextNumber = Me.ID
Forms(strDocName)!ID = strNextNumber
 
M

Marshall Barton

reservedbcreater said:
Private Sub Form_Load()

Dim strNextNumber As String

strNextNumber = Nz(DMax("ID", "General Housing Survey"), 0) + 1

strNextNumber = Me.ID

End Sub

?????
i want it to read the General Housing Table ID field and get the highest
number and then increment it by 1 and then fill in the ID field
automatically on the form with the new number opon it opening


You have the second line backwards. It should be:

Me.ID = strNextNumber

BUT, you do NOT want to do this unless you are certain that
the form is on a new record. It would be more than a little
disasterous to do that to an existing record.
 
J

Joe Holzhauer

See responses inline below:
Private Sub Form_Load()

Dim strNextNumber As String
Are you sure you want this to be a string variable? If you're numerically
incrementing it, it might make more sense if it were a Long. What data type
is your ID field within the table?
strNextNumber = Nz(DMax("ID", "General Housing Survey"), 0) + 1
I honestly don't know if it makes a difference in this context, but usually
when there are spaces within an object name, you should enclose the name in
brackets:
....DMax("ID", "[General Housing Survey]")...
strNextNumber = Me.ID
I think you want this to be reversed, as in:
Me.ID = strNextNumber
otherwise, you're just overwriting your variable with the contents of the ID
field.
End Sub

?????
i want it to read the General Housing Table ID field and get the highest
number and then increment it by 1 and then fill in the ID field
automatically on the form with the new number opon it opening

Hope this helps,
Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top