Question

I have a table (id, Name, Surname, Address etc.). All the fields (except id) can be NULL. I want to make a form where I can find all the records that have at least a NULL field. I have made a query (with the query designer) and then I "linked" a continuous form to it.

In the Detail part of the form I put a textbox ID (linked to the query) so I can have all the IDs that have at least a field NULL. So far so good, it works.

I would like to inform the user, after the ID, which fields are blank. So I put another textbox (named txt) and making controls like If isNull(Me.Name) then Me.txt.Value ="Name field is blank". It works perfectly but only for the first record. All the other records have the same message in the textbox txt.

The code is like this (of course stringW and lngth are declared)

If IsNull(Me.Name.Value) Then
stringW = stringW & " Name field,"
End If

..... (the same for Surname, Tel number etc)

lngth = Len(stringW) - 1
stringW = Left$(stringW, lngth)
Me.txt.Value = stringW

It seems that the form loads (I put the code in the load section), it makes the controls once and then copies the content of the stringW in the txt textbox for every record.

How could I resolve it? I mean, how can I have a textbox in the continuous form that changes its' contents informing the user for the blank fields of the record?

Was it helpful?

Solution 2

The problem here is that an unbound Text Box on a form that is displayed as Continuous Forms will always display the same value for every record. Any VBA manipulations you might apply to the unbound Text Box will only use the data from the current record.

A workaround for this would be to create a saved query in Access that calculates the status for each record, then base your form on the query and have the Text Box bound to the calculated [EmptyFields] field.

That is, for the sample data in [Table1]

id  Name   Surname   Address              
--  -----  --------  ---------------------
 1  Gord   Thompson  123 Main St          
 2  Homer            742 Evergreen Terrace
 3         Flanders                       

you could create a saved query like this

SELECT 
    [id],
    [Name],
    [Surname],
    [Address],
    Mid(IIf(IsNull([Name]),", Name","") & IIf(IsNull([Surname]),", Surname","") & IIf(IsNull([Address]),", Address",""),3) AS EmptyFields
FROM Table1

which returns

id  Name   Surname   Address                EmptyFields  
--  -----  --------  ---------------------  -------------
 1  Gord   Thompson  123 Main St                         
 2  Homer            742 Evergreen Terrace  Surname      
 3         Flanders                         Name, Address

and you could use that query as the Record Source for your form.

OTHER TIPS

I understand this is over a year old, but I had the same issue and found a solution.

Simply write a function that creates the string you want, which uses values from your form. So instead of:

Me.Name.Value

You would use:

Forms!FormName!ControlName.Value

Then simply use the function as the ControlSource for your unbound textbox. You do this by clicking on the "..." on ControlSource, then choose "Functions", then your module, then the function itself. Works perfectly for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top