Visual Basic in Access Question

J

jimswinder

I want the Control Source (or perhaps it should be the "Default Value") in a
form to be the following using VB.

Go to the last record in "Table A" "FieldName" and add "1" .

So if the last record in "Table A" "FieldName" equals "123456" it would
display "123457" on the form.

Suggestions???
 
J

jimswinder

I don't think this application will work for what I need to do since I am
looking at a table and this seems to bringing in the number from the same
form. Or maybe I am missing something..which happens quite often.
 
K

Klatuu

Set rst = CurrentDB.OpenRecordset("Table A", dbOpenDynaset)
With rst
If Not .EOF Then
.MoveLast
![FieldName] = ![FieldName] + 1
.Update
End If
.Close
End With
Set rst = Nothing
 
S

SusanV

Hi Jim,

You can use DMax for this, such as:

me.textbox = DMax("fieldname", "tableA") + 1
 
S

Sprinks

Unless I'M missing something, it should work for you. The syntax of the DMax
function is:

DMax(expr, domain, [criteria])

expr is an expression representing a *table* field
domain is a string expression for a *table* or *query*

It necessarily have any relationship to the current form.

Sprinks
 
J

jimswinder

Sorry...didn't work. Field comes up blank...

Klatuu said:
Set rst = CurrentDB.OpenRecordset("Table A", dbOpenDynaset)
With rst
If Not .EOF Then
.MoveLast
![FieldName] = ![FieldName] + 1
.Update
End If
.Close
End With
Set rst = Nothing

jimswinder said:
I want the Control Source (or perhaps it should be the "Default Value") in a
form to be the following using VB.

Go to the last record in "Table A" "FieldName" and add "1" .

So if the last record in "Table A" "FieldName" equals "123456" it would
display "123457" on the form.

Suggestions???
 
Top