Help with code.

I

Iram

Hello.
I am a dork. I am trying to get a button on a form to perform three
different tasks. Below is a mesh of three codes that I got from different
buttons. The button name is "Siguiente Pagina".

I need the button to perform the following...

1. Create a code using the vba- this works fine.
2. Render the data on the form to the table- i don't think this is working.
3. Open a form called "frm_AltaDeRegistrosPagina3-Cuestionario"- this is not
working.


Can you help me figure out what is wrong?


Thank you,
Iram Alvarez


Private Sub Siguiente_Pagina_Click()
On Error GoTo HandleErr

Dim tmpStr As String
Dim sP As String
Dim sM As String
Dim sN As String
Dim dtFECHADENACIMIENTO As String
Dim sC As String
Dim i As Integer
Dim OK As Boolean
Dim stDocName As String
Dim stLinkCriteria As String

OK = False

'get first letter of ApellidoPaterno
sP = UCase(Left(Me.ApellidoPaterno, 1))

'loop thru the name starting at the second letter
For i = 2 To Len(Me.ApellidoPaterno)
tmpStr = UCase(Mid(Me.ApellidoPaterno, i, 1))
'is letter in the string?
OK = InStr(1, "AEIOU", tmpStr)

If OK Then
'found a vowel - get out
Exit For
End If
Next

'get second letter of ApellidoPaterno
If OK Then
'vowel
sP = sP & tmpStr
Else
'no vowel
sP = sP & UCase(Mid(Me.ApellidoPaterno, 2, 1))
End If

' get letter from ApellidoMaterno
If Len(Trim(Nz(Me.ApellidoMaterno, ""))) > 0 Then
sM = UCase(Left(Me.ApellidoMaterno, 1))
End If

' get letter from Nombre
If Len(Trim(Nz(Me.Nombre, ""))) > 0 Then
sN = UCase(Left(Me.Nombre, 1))
End If


'process FECHADENACIMIENTO
dtFECHADENACIMIENTO = Format(Month(Me.FechaDeNacimiento), "00") & _
Format(Day(Me.FechaDeNacimiento), "00") & _
Right(Year(Me.FechaDeNacimiento), 2)

'add them together
Me.Codigo = sP & sM & sN & "-" & dtFECHADENACIMIENTO

Handle_Exit:
Exit Sub

HandleErr:
MsgBox Err.Number, Err.Description
Resume Handle_Exit


Me.Dirty = False


stDocName = "frm_AltaDeRegistrosPagina3-Cuestionario"

stLinkCriteria = "[Codigo]=" & "'" & Me![Codigo] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Siguiente_Pagina_Click:
Exit Sub




End Sub
 
G

Graham Mandeno

Hi Iram

Your code is never getting as far as "Me.Dirty = False" because that code is
below the exit point of your procedure.

You need to move this code:
Me.Dirty = False


stDocName = "frm_AltaDeRegistrosPagina3-Cuestionario"

stLinkCriteria = "[Codigo]=" & "'" & Me![Codigo] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

and place it above Handle_Exit.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Iram said:
Hello.
I am a dork. I am trying to get a button on a form to perform three
different tasks. Below is a mesh of three codes that I got from different
buttons. The button name is "Siguiente Pagina".

I need the button to perform the following...

1. Create a code using the vba- this works fine.
2. Render the data on the form to the table- i don't think this is
working.
3. Open a form called "frm_AltaDeRegistrosPagina3-Cuestionario"- this is
not
working.


Can you help me figure out what is wrong?


Thank you,
Iram Alvarez


Private Sub Siguiente_Pagina_Click()
On Error GoTo HandleErr

Dim tmpStr As String
Dim sP As String
Dim sM As String
Dim sN As String
Dim dtFECHADENACIMIENTO As String
Dim sC As String
Dim i As Integer
Dim OK As Boolean
Dim stDocName As String
Dim stLinkCriteria As String

OK = False

'get first letter of ApellidoPaterno
sP = UCase(Left(Me.ApellidoPaterno, 1))

'loop thru the name starting at the second letter
For i = 2 To Len(Me.ApellidoPaterno)
tmpStr = UCase(Mid(Me.ApellidoPaterno, i, 1))
'is letter in the string?
OK = InStr(1, "AEIOU", tmpStr)

If OK Then
'found a vowel - get out
Exit For
End If
Next

'get second letter of ApellidoPaterno
If OK Then
'vowel
sP = sP & tmpStr
Else
'no vowel
sP = sP & UCase(Mid(Me.ApellidoPaterno, 2, 1))
End If

' get letter from ApellidoMaterno
If Len(Trim(Nz(Me.ApellidoMaterno, ""))) > 0 Then
sM = UCase(Left(Me.ApellidoMaterno, 1))
End If

' get letter from Nombre
If Len(Trim(Nz(Me.Nombre, ""))) > 0 Then
sN = UCase(Left(Me.Nombre, 1))
End If


'process FECHADENACIMIENTO
dtFECHADENACIMIENTO = Format(Month(Me.FechaDeNacimiento), "00") & _
Format(Day(Me.FechaDeNacimiento), "00") & _
Right(Year(Me.FechaDeNacimiento), 2)

'add them together
Me.Codigo = sP & sM & sN & "-" & dtFECHADENACIMIENTO

Handle_Exit:
Exit Sub

HandleErr:
MsgBox Err.Number, Err.Description
Resume Handle_Exit


Me.Dirty = False


stDocName = "frm_AltaDeRegistrosPagina3-Cuestionario"

stLinkCriteria = "[Codigo]=" & "'" & Me![Codigo] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Siguiente_Pagina_Click:
Exit Sub




End Sub
 
I

Iram

Now I that I moved according to your instructions the debug doesn't like the
below....

MsgBox Err.Number, Err.Description


This is what all of the code looks like...

Private Sub Siguiente_Pagina_Click()
On Error GoTo HandleErr

Dim tmpStr As String
Dim sP As String
Dim sM As String
Dim sN As String
Dim dtFECHADENACIMIENTO As String
Dim sC As String
Dim i As Integer
Dim OK As Boolean
Dim stDocName As String
Dim stLinkCriteria As String

OK = False

'get first letter of ApellidoPaterno
sP = UCase(Left(Me.ApellidoPaterno, 1))

'loop thru the name starting at the second letter
For i = 2 To Len(Me.ApellidoPaterno)
tmpStr = UCase(Mid(Me.ApellidoPaterno, i, 1))
'is letter in the string?
OK = InStr(1, "AEIOU", tmpStr)

If OK Then
'found a vowel - get out
Exit For
End If
Next

'get second letter of ApellidoPaterno
If OK Then
'vowel
sP = sP & tmpStr
Else
'no vowel
sP = sP & UCase(Mid(Me.ApellidoPaterno, 2, 1))
End If

' get letter from ApellidoMaterno
If Len(Trim(Nz(Me.ApellidoMaterno, ""))) > 0 Then
sM = UCase(Left(Me.ApellidoMaterno, 1))
End If

' get letter from Nombre
If Len(Trim(Nz(Me.Nombre, ""))) > 0 Then
sN = UCase(Left(Me.Nombre, 1))
End If


'process FECHADENACIMIENTO
dtFECHADENACIMIENTO = Format(Month(Me.FechaDeNacimiento), "00") & _
Format(Day(Me.FechaDeNacimiento), "00") & _
Right(Year(Me.FechaDeNacimiento), 2)

'add them together
Me.Codigo = sP & sM & sN & "-" & dtFECHADENACIMIENTO

Me.Dirty = False


stDocName = "frm_AltaDeRegistrosPagina3-Cuestionario"

stLinkCriteria = "[Codigo]=" & "'" & Me![Codigo] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Handle_Exit:
Exit Sub

HandleErr:
MsgBox Err.Number, Err.Description
Resume Handle_Exit


Exit_Siguiente_Pagina_Click:
Exit Sub

End Sub


Can you help me fix this?

Thanks.
Iram








Graham Mandeno said:
Hi Iram

Your code is never getting as far as "Me.Dirty = False" because that code is
below the exit point of your procedure.

You need to move this code:
Me.Dirty = False


stDocName = "frm_AltaDeRegistrosPagina3-Cuestionario"

stLinkCriteria = "[Codigo]=" & "'" & Me![Codigo] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

and place it above Handle_Exit.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Iram said:
Hello.
I am a dork. I am trying to get a button on a form to perform three
different tasks. Below is a mesh of three codes that I got from different
buttons. The button name is "Siguiente Pagina".

I need the button to perform the following...

1. Create a code using the vba- this works fine.
2. Render the data on the form to the table- i don't think this is
working.
3. Open a form called "frm_AltaDeRegistrosPagina3-Cuestionario"- this is
not
working.


Can you help me figure out what is wrong?


Thank you,
Iram Alvarez


Private Sub Siguiente_Pagina_Click()
On Error GoTo HandleErr

Dim tmpStr As String
Dim sP As String
Dim sM As String
Dim sN As String
Dim dtFECHADENACIMIENTO As String
Dim sC As String
Dim i As Integer
Dim OK As Boolean
Dim stDocName As String
Dim stLinkCriteria As String

OK = False

'get first letter of ApellidoPaterno
sP = UCase(Left(Me.ApellidoPaterno, 1))

'loop thru the name starting at the second letter
For i = 2 To Len(Me.ApellidoPaterno)
tmpStr = UCase(Mid(Me.ApellidoPaterno, i, 1))
'is letter in the string?
OK = InStr(1, "AEIOU", tmpStr)

If OK Then
'found a vowel - get out
Exit For
End If
Next

'get second letter of ApellidoPaterno
If OK Then
'vowel
sP = sP & tmpStr
Else
'no vowel
sP = sP & UCase(Mid(Me.ApellidoPaterno, 2, 1))
End If

' get letter from ApellidoMaterno
If Len(Trim(Nz(Me.ApellidoMaterno, ""))) > 0 Then
sM = UCase(Left(Me.ApellidoMaterno, 1))
End If

' get letter from Nombre
If Len(Trim(Nz(Me.Nombre, ""))) > 0 Then
sN = UCase(Left(Me.Nombre, 1))
End If


'process FECHADENACIMIENTO
dtFECHADENACIMIENTO = Format(Month(Me.FechaDeNacimiento), "00") & _
Format(Day(Me.FechaDeNacimiento), "00") & _
Right(Year(Me.FechaDeNacimiento), 2)

'add them together
Me.Codigo = sP & sM & sN & "-" & dtFECHADENACIMIENTO

Handle_Exit:
Exit Sub

HandleErr:
MsgBox Err.Number, Err.Description
Resume Handle_Exit


Me.Dirty = False


stDocName = "frm_AltaDeRegistrosPagina3-Cuestionario"

stLinkCriteria = "[Codigo]=" & "'" & Me![Codigo] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Siguiente_Pagina_Click:
Exit Sub




End Sub
 
I

Iram

Actually the reason why it didn't like this line was because I left a few
required fields blank so it gave a debug error. Is there any way that we can
replace the debug error if the required fields are left blank with something
like "Please enter your First, Last and middle initial?


Thanks.
Iram




Iram said:
Now I that I moved according to your instructions the debug doesn't like the
below....

MsgBox Err.Number, Err.Description


This is what all of the code looks like...

Private Sub Siguiente_Pagina_Click()
On Error GoTo HandleErr

Dim tmpStr As String
Dim sP As String
Dim sM As String
Dim sN As String
Dim dtFECHADENACIMIENTO As String
Dim sC As String
Dim i As Integer
Dim OK As Boolean
Dim stDocName As String
Dim stLinkCriteria As String

OK = False

'get first letter of ApellidoPaterno
sP = UCase(Left(Me.ApellidoPaterno, 1))

'loop thru the name starting at the second letter
For i = 2 To Len(Me.ApellidoPaterno)
tmpStr = UCase(Mid(Me.ApellidoPaterno, i, 1))
'is letter in the string?
OK = InStr(1, "AEIOU", tmpStr)

If OK Then
'found a vowel - get out
Exit For
End If
Next

'get second letter of ApellidoPaterno
If OK Then
'vowel
sP = sP & tmpStr
Else
'no vowel
sP = sP & UCase(Mid(Me.ApellidoPaterno, 2, 1))
End If

' get letter from ApellidoMaterno
If Len(Trim(Nz(Me.ApellidoMaterno, ""))) > 0 Then
sM = UCase(Left(Me.ApellidoMaterno, 1))
End If

' get letter from Nombre
If Len(Trim(Nz(Me.Nombre, ""))) > 0 Then
sN = UCase(Left(Me.Nombre, 1))
End If


'process FECHADENACIMIENTO
dtFECHADENACIMIENTO = Format(Month(Me.FechaDeNacimiento), "00") & _
Format(Day(Me.FechaDeNacimiento), "00") & _
Right(Year(Me.FechaDeNacimiento), 2)

'add them together
Me.Codigo = sP & sM & sN & "-" & dtFECHADENACIMIENTO

Me.Dirty = False


stDocName = "frm_AltaDeRegistrosPagina3-Cuestionario"

stLinkCriteria = "[Codigo]=" & "'" & Me![Codigo] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria


Handle_Exit:
Exit Sub

HandleErr:
MsgBox Err.Number, Err.Description
Resume Handle_Exit


Exit_Siguiente_Pagina_Click:
Exit Sub

End Sub


Can you help me fix this?

Thanks.
Iram








Graham Mandeno said:
Hi Iram

Your code is never getting as far as "Me.Dirty = False" because that code is
below the exit point of your procedure.

You need to move this code:
Me.Dirty = False


stDocName = "frm_AltaDeRegistrosPagina3-Cuestionario"

stLinkCriteria = "[Codigo]=" & "'" & Me![Codigo] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

and place it above Handle_Exit.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Iram said:
Hello.
I am a dork. I am trying to get a button on a form to perform three
different tasks. Below is a mesh of three codes that I got from different
buttons. The button name is "Siguiente Pagina".

I need the button to perform the following...

1. Create a code using the vba- this works fine.
2. Render the data on the form to the table- i don't think this is
working.
3. Open a form called "frm_AltaDeRegistrosPagina3-Cuestionario"- this is
not
working.


Can you help me figure out what is wrong?


Thank you,
Iram Alvarez


Private Sub Siguiente_Pagina_Click()
On Error GoTo HandleErr

Dim tmpStr As String
Dim sP As String
Dim sM As String
Dim sN As String
Dim dtFECHADENACIMIENTO As String
Dim sC As String
Dim i As Integer
Dim OK As Boolean
Dim stDocName As String
Dim stLinkCriteria As String

OK = False

'get first letter of ApellidoPaterno
sP = UCase(Left(Me.ApellidoPaterno, 1))

'loop thru the name starting at the second letter
For i = 2 To Len(Me.ApellidoPaterno)
tmpStr = UCase(Mid(Me.ApellidoPaterno, i, 1))
'is letter in the string?
OK = InStr(1, "AEIOU", tmpStr)

If OK Then
'found a vowel - get out
Exit For
End If
Next

'get second letter of ApellidoPaterno
If OK Then
'vowel
sP = sP & tmpStr
Else
'no vowel
sP = sP & UCase(Mid(Me.ApellidoPaterno, 2, 1))
End If

' get letter from ApellidoMaterno
If Len(Trim(Nz(Me.ApellidoMaterno, ""))) > 0 Then
sM = UCase(Left(Me.ApellidoMaterno, 1))
End If

' get letter from Nombre
If Len(Trim(Nz(Me.Nombre, ""))) > 0 Then
sN = UCase(Left(Me.Nombre, 1))
End If


'process FECHADENACIMIENTO
dtFECHADENACIMIENTO = Format(Month(Me.FechaDeNacimiento), "00") & _
Format(Day(Me.FechaDeNacimiento), "00") & _
Right(Year(Me.FechaDeNacimiento), 2)

'add them together
Me.Codigo = sP & sM & sN & "-" & dtFECHADENACIMIENTO

Handle_Exit:
Exit Sub

HandleErr:
MsgBox Err.Number, Err.Description
Resume Handle_Exit


Me.Dirty = False


stDocName = "frm_AltaDeRegistrosPagina3-Cuestionario"

stLinkCriteria = "[Codigo]=" & "'" & Me![Codigo] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Siguiente_Pagina_Click:
Exit Sub




End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top