Troubles displaying null values

ReaperFett
04-15-2004, 03:22 PM
Okay I have a table of data, and when I click on an entry I want it to appear in a series of text boxes. The code goes as follows:

Private Sub grdDataGrid_Click()
DisplayID = adoPrimaryRS!ID
Displayname = adoPrimaryRS!name
DisplayAddress = adoPrimaryRS!Address
DisplayEmail = adoPrimaryRS!Email
End Sub
Now this does work, it displays them as planned. However the problem occurs when I click on an entry that has a null value, causing an error to occur.

Does anyone know what I'm doing wrong?

LaVolpe
04-15-2004, 03:25 PM
Keep this little trick handy when trying to display fields that can be null. One way is to test for null by using If IsNull(field) then do something different. But the quick & easy way is to append an vbNullString to th end of those fields:
DisplayEmail = adoPrimaryRS!Email & ""

msmeth
04-15-2004, 03:26 PM
Okay I have a table of data, and when I click on an entry I want it to appear in a series of text boxes. The code goes as follows:

Private Sub grdDataGrid_Click()
DisplayID = adoPrimaryRS!ID
Displayname = adoPrimaryRS!name
DisplayAddress = adoPrimaryRS!Address
DisplayEmail = adoPrimaryRS!Email
End Sub
Now this does work, it displays them as planned. However the problem occurs when I click on an entry that has a null value, causing an error to occur.

Does anyone know what I'm doing wrong?

I think it's because the textboxes don't accept Nulls. They accept empty strings though, so try:


DisplayID = "" & adoPrimaryRS!ID
Displayname = "" & adoPrimaryRS!name
DisplayAddress = "" & adoPrimaryRS!Address
DisplayEmail = "" & adoPrimaryRS!Email

ReaperFett
04-15-2004, 03:28 PM
So they accept nothing, but not nothing :)

Thanks both of you :)

LaVolpe
04-15-2004, 03:31 PM
So they accept nothing, but not nothing
Almost, they accept nothing, but not null :cool:

reboot
04-15-2004, 03:33 PM
Not quite right. They will accept an empty string, but not null. They are not the same thing.

ReaperFett
04-15-2004, 03:56 PM
Right.

ReaperFett
04-15-2004, 04:07 PM
This is a related problem to this, but not about null.

After inputting the data, you can edit it and then save it. The code goes as follows:

Private Sub SaveChangesButton_Click()
Reply = MsgBox("Are you sure you wish to edit this member's details?", 1, "Edit?")
If Reply = 1 Then

adoPrimaryRS.Edit
adoPrimaryRS!Forename = DisplayForename
adoPrimaryRS!Surname = DisplaySurname
adoPrimaryRS!PhoneNumber = DisplayPhone
adoPrimaryRS!Email = DisplayEmail
adoPrimaryRS!Street = DisplayStreet
adoPrimaryRS!Town = DisplayTown
adoPrimaryRS!County = DisplayCounty
adoPrimaryRS!Postcode = DisplayPostcode
adoPrimaryRS.Update
MsgBox "Member details updated!", 64, "Success!"

Exit Sub
End If
End Sub

But when I press save, it says "Compile error: Method or data member not found". Clicking okay it has the Private sub line highlighted in yellow, with .Edit highlighted in blue. What did I screw up?

reboot
04-15-2004, 04:33 PM
There's no .Edit in ADO. You don't need it.

ReaperFett
04-15-2004, 04:37 PM
So I just remove that line? Okay thanks :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum