By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

null problem

Kaosu
P: 19
I am trying to get the database to display the picture of the person on the current record and if not to display the company logo.

At the moment I cant get the form to recognise the value as Null and not try and display a picture that does not exist bringing up a 2220 runtime error.



Private Sub Form_Current()

imgTxt.Value = "W:\training database\Pictures\" & SQSID & ".jpg"

If imgTxt.Value = Null Then
Pic.Picture = "W:\training database\Pictures\sqs.bmp"
Else
Pic.Picture = imgTxt.Value
End If

End Sub
Oct 10 '07 #1
Share this Question
Share on Google+
5 Replies


Jim Doherty
Expert 100+
P: 897
I am trying to get the database to display the picture of the person on the current record and if not to display the company logo.

At the moment I cant get the form to recognise the value as Null and not try and display a picture that does not exist bringing up a 2220 runtime error.



Private Sub Form_Current()

imgTxt.Value = "W:\training database\Pictures\" & SQSID & ".jpg"

If imgTxt.Value = Null Then
Pic.Picture = "W:\training database\Pictures\sqs.bmp"
Else
Pic.Picture = imgTxt.Value
End If

End Sub

Change
Expand|Select|Wrap|Line Numbers
  1.  If imgTxt.Value = Null 
to
Expand|Select|Wrap|Line Numbers
  1.  If IsNull(Me!img) Then
Oct 10 '07 #2

Kaosu
P: 19
the imgTxt is actualy a txtbox with the path for the img.
i changed the code to

If IsNull(Me!imgTxt) Then

but its still skipping the null, bring up the runtime error and stating that...

imgTxt = "W:\training database\Pictures\" & SQSID & ".jpg"
......

Pic.Picture = imgTxt.Value


is missing
Oct 10 '07 #3

Jim Doherty
Expert 100+
P: 897
the imgTxt is actualy a txtbox with the path for the img.
i changed the code to

If IsNull(Me!imgTxt) Then

but its still skipping the null, bring up the runtime error and stating that...

imgTxt = "W:\training database\Pictures\" & SQSID & ".jpg"
......

Pic.Picture = imgTxt.Value

is missing
If its skipping over the true part of the IF expression then it means it isnt null

leave the word VALUE out just refer to the control Me!imgtxt

You might want to consider also doubling up on the first if statement to take account of any zero length string

If IsNull(Me!imgTxt) Or Me!imgTxt ="" THEN

Wheres is the value SQSID coming from?and also when using a textbox or any other control on a form get into the habit of including a reference to the form on which the textbox is mounted using the ME keyword

Regards

Jim
Oct 10 '07 #4

Kaosu
P: 19
Wheres is the value SQSID coming from?and also when using a textbox or any other control on a form get into the habit of including a reference to the form on which the textbox is mounted using the ME keyword
"W:\training database\Pictures\" & SQSID & ".jpg"

"SQSID" is the name of the key field.
each persons picture is numbered with their company id so that when the picture is put into the folder it will automatically show up when scrolling through the records (if i ever get it to work).

just tested it and its still not working with

If IsNull(Me!imgTxt) Or Me!imgTxt ="" THEN

its still trying to find the path of a file that doesn't exist.
is null even the right statement to be using?

i highlighted the Me!imgTxt and saw

Me!imgTxt = "W:\training database\Pictures\3.jpg"
(i only have 2 jpg's in the folder atm so 3 does not exist)


and i think the problem is that even though the file does not exist the path is still stored in the txtbox.
is there another way of checking if that file exists or not?
Oct 10 '07 #5

Kaosu
P: 19
after another hard days work browsing google i got it to work.

Private Sub Form_Current()

If Dir("W:\training database\Pictures\" & SQSID & ".jpg", vbNormal) <> "" Then
Me!imgTxt = "W:\training database\Pictures\" & SQSID & ".jpg"
Else
Me!imgTxt = ""
End If

If IsNull(Me!imgTxt) Or Me!imgTxt = "" Then
Pic.Picture = "W:\training database\Pictures\sqs.bmp"
Else
Pic.Picture = imgTxt

End If

End Sub


thx for ur input jim
Oct 10 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.