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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with Me code

Status
Not open for further replies.

Schaap

Technical User
Jul 6, 2004
54
NL
I'm still a newbie and got a problem with a loop were I use Me.fieldname. I load a form where the user can fill in some fields. I read these fields one by one with Me.fieldname. I read those fieldnames in a loop.
The problem is that the user never can fill in all the fields at once (that's why I use the loop), but then I get fieldnames (not filled in yet) with the value "null".
And that's not accepted by access 2000.

Please let me know what to do !

See the code below :

Private Sub Form_Load()

Knop82.Tag = "Go"

Do
InvestName = Me.NewInvestmentNaam
BudgetY = Me.NewBudgetJaar
InvestPurpose = Me.NewInvestmentDoel
Necess = Me.NewNecessity
InvestDescrip = Me.NewInvestmentDescription
TestDescrip = Me.NewTestDescription
Howtest = Me.NewHowTestingNow
InvestReal = Me.NewInvestmentRealisation
Loop Until Knop82.Tag = "Stop"
End Sub
 
Hi Schaap!

What you may want to do is use an if..then clause to fill in the variables. For example, if your InvestName is a string variable you can say something like:

If Me.NewInvestmentNaam = "" Then
InvestName = ""
Else
InvestName = Me.NewInvestmentNaam
End If

Continue to do this for all the fields that are not required for assignment in the loop. This way the variable won't be "null", it will be an empty string. Hope it helps!
 
THanx Marina,

but I still got to use the loop I think !
Because the user who's gonna fill in the fields can't fill in all the fields at once. And the program runs fast through the code so if I don't use the loop the code writes "" before the user get's the possibility to fill in the field !!!

If I got it wrong, please let me know.
 
I tried and I tried but it didn't work !

I used Marina's If THen Else in my Loop.
And I don't know what the problem is but the If Then Else lop doesn't work well.
The code never comes in the Then part of the loop !!!
I tried it with = "" and = Null ans used also If Not IsNull ..... .

See code below :

Do
If (Me.NewInvestmentNaam) = "" Then
InvestName = ""
Else
InvestName = Me.NewInvestmentNaam
End If
'InvestName = Me.NewInvestmentNaam
If Me.NewBudgetJaar = Null Then
BudgetY = ""
Else
BudgetY = Me.NewBudgetJaar
End If
'BudgetY = Me.NewBudgetJaar
If Me.NewInvestmentDoel = Null Then
InvestPurpose = ""
Else
InvestPurpose = Me.NewInvestmentDoel
End If
'InvestPurpose = Me.NewInvestmentDoel
If Me.NewNecessity = Null Then
Necess = ""
Else
Necess = Me.NewNecessity
End If

What kin of stupid thing do I wrong ?????
 
Private Sub Form_Load()
You really expect the user fills fields during this event ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Schaap,

Your best bet would be to place that code into another event rather than the Form_Load (as PHV is suggesting). You could place a command button (for example) on your form and have the user press that button when they want to perform an action. That way you will give the user enough time to enter the values they want and you can use your loop with the if...then clause to assign values to your variables.
 
Ok,

I all ready had a save command button that the user have to press. But it wasn't possible to put the code under this button.
But I change a lot and now the If..then clause is put under this save button.
And sorry if I ask too much but still the if...then clause doesn't function OK !

The problem is that if the user doesn't fill in a field the code has to follow the Then-tree (because Null=Null) !
But the code follows the Else-tree in stead of Then ????
Please let me know to get it right.

Code :

If Me.NewBudgetJaar = Null Then
NoInputStr = NoInputStr & "'" & "Budget Year"
GoTo Line1
Else
If Me.NewInvestmentDoel = Null Then
NoInputStr = NoInputStr & "'" & "Investment Purpose"
GoTo Line1
Else
and so on, after the last else I put the data into a new record.
 
You can't test for Null that way, use for instance

[tt]if (isnull( Me.NewInvestmentDoel)) then ' or
if (len(trim$(Me.NewInvestmentDoel & vbnullstring))>0) then[/tt]

But what's really stumping me here, is; What are you trying to do?

The code is looping just one record, and per each loop throwing the same values into some variables, form controsl (or whatever those undeclared thingies are).

I you'd just explained what you're trying to do, we might perhaps assist, but as it is, I must confess I don't understand a thing.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top