Access 2013 and IF statments

play2mefish

New member
Local time
Yesterday, 15:07
Joined
Oct 7, 2013
Messages
6
Hello everyone, first I would like to thank this board for all of the help I have received before I ever signed up so I could post my questions. Over the years I have always found a solution on this forum for everytime I had a problem. But now I have an issue and I can not for the life of me figure out what is happening and why it isn't working the way I think it should. Here is the code that I'm using for a command button:

Private Sub Command163_Click()

If IsNull([PC_Serial_Number]) Then
MsgBox "This record does not have a serial number."
MsgBox "msg box 1, this is the message after no serial number"
GoTo finish:
End If

If Not Me.PC_Make = "DELL" Then
MsgBox "This is not a DELL Workstation, it is a " & PC_Make & " Workstation!"
MsgBox "msg box 2 , this is the message after not dell"
GoTo finish:
End If

If Me.PC_Make = "DELL" And IsNull(Me.PC_Serial_Number) Then
GoTo finish:
Else
'I know the hyperlinkaddress works but this site would not let me post the hyperlink...this line added for clarification and not part of the code
Me.Command163.HyperlinkAddress =dell website with serial number & Me.PC_Serial_Number
End If

finish:
MsgBox "msg box 3 this is the contents of the last msg box " & Me.PC_Make
End Sub

The problem I'm experiencing is this, While on my form I have a command button that will check to see if the PC_Make is DELL and if there is no serial number, then pop up the message to tell me there is no serial number. Works OK if that is all I do.

If I switch to another record, that has cisco, again it will pop up the message and tell me it is not a dell, and will exit. Works OK if that is all I do.

If I switch to another record that has dell and a serial number in the serial number field, it will follow the hyperlink to dell and to the serial number of the pc. It works OK if that is all I do.

If I check a workstation that has dell and a serial number, then click out of the IE web page, and then switch records, that has cisco listed as pc_make instead of dell, my msgbox will popup and tell me it is not a dell, and when I click OK, it will start the hyperlink with the known last dell and serial number. If I change to another record that has dell and a serial number, it will bring up the new page on DELLs website as advertised. If I switch to another record that has DELL and NO serial number, it will prompt me like it is working, but when I click OK to exit the message, off I go to DELL so it can show me the last record that I clicked that had DELL and a serial number.

I hope this makes sense to someone. I have tried using one IF statement and multiple Else If statements, so far I've gotten the same results no matter how I have tried. The purpose of the extra msgbox 1 and 2 and so forth is so I can tell where I'm at in the code.

Anyway, I'm open to all suggestions and will try anything. Thanks for listening.
 
When you need to use several conditions I would use the Select Case statement. You can even nest several select cases...
For example:

Code:
Select Case Me.PC_Make
[INDENT]Case "DELL"
[INDENT]msgbox "I'am a Dell"
Select Case Nz(PC_SERIAL_NUMBER,"")
[INDENT]Case ""
[INDENT]msgbox "No serial number"
[/INDENT]Case else
[INDENT]'Goto website....
[/INDENT][/INDENT][/INDENT]Case "HP"
Case Else
[/INDENT]End Select
 
JackKaptijn,

Thanks for the reply. I tried your suggestion of the CASE statement, and I got the same results. If a record matches DELL and has a serial number it goes to the web site as advertised. If I switch records to a Cisco and no serial number, it will still start the DELL web site with the last record that worked. Somehow it is remembering the last DELL and SERIAL number and will go to the WEB site even the current record is not dell and has no serial number.

I'll keep prodding along and see what I can do to resolve this. Thanks again.
 
I have finally solved this issue. It appears that the me.command163.hyperlinkaddress was the issue. As it would always remember the last record that would work. So, I changed the me.command163.hyperlinkaddress to a shell. Here is the code that worked:

Dim strdell As String

strdell = "your web address here " &
Me.PC_Serial_Number

If IsNull([PC_Serial_Number]) Then
MsgBox "This record does not have a serial number."
GoTo finish
End If

If Not Me.PC_Make = "DELL" Then
MsgBox "This is not a DELL Workstation, it is a " & PC_Make & " Workstation!"
GoTo finish
End If

If Me.PC_Make = "DELL" And IsNull(Me.PC_Serial_Number) Then
GoTo finish
Else
Shell "C:\Program Files\Internet Explorer\iexplore.exe " & strdell
End If

finish:
strdell = ""


As JackKaptijn suggested, I could of used a CASE statement as well and it would work as long as I did the Shell to Internet Explorer and not use the hyperlinkaddress.

Thanks to all.
 

Users who are viewing this thread

Back
Top Bottom